string to int

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello I communicate through a translator because I am from Ukraine. so I'll try to write my mistake more affordable.
I'm posting from Uart characters write them in time. characters must be converted to an integer and perform mathematical operations on them. for example, I sent values of 15.35 and I want to add to the first and the second number to 10.
  15 + 10 = 25
  35 + 10 = 45
bring them to the screen
I do accept values

   

#define BUF_SIZE 128
char buf[BUF_SIZE];
unsigned int buf_cnt = 0;

   

****************

   

int main( void )
{
uart_init();uart_init();
uart_puts( "Hello Andriy\r\n" );

   

while(1)
    {

   

char c= uart_getc();
        
        
if( (c == '\n') || ( c == '\r' ) )
         {
buf[buf_cnt] = 0;
buf_cnt = 0;
uart_puts(buf);
            }
else
                    {
if( buf_cnt < BUF_SIZE )
                        {
buf[buf_cnt] = c;
buf_cnt++;
                            
                        }
                    }
        
        
    }
}

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum!

   

Use atoi() macro for string conversion. Have a look into this C-manual.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I tried to use atoi() and it's did't work, can you write me code, please?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I cannot, I do not have a PSoC1 at hand to test check internet for yourself.

   

What error have you got?

   

 

   

Bob