3 Replies Latest reply on Feb 13, 2016 7:35 AM by user_1377889

    string to int

    asdbumer1_1584296

      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++;
                                  
                              }
                          }
              
              
          }
      }