Convert string to int in PSOC designer

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

cross mob
Anonymous
Not applicable

Hi everyone,

   

I try to receive some parameter through UART and convert them into int, but when I try to assign the conversion value to the internal registers, there is a error message;  I guess I missed something important about the data type, can anyone give me some suggestion?  Thank you!

   

 

   

char * string;

   

int parameter = 0;

   

while(string = UART_szGetParam()) {
                   
                    for (j=0; j<4; j++)
                      UART_CPutString(" <");
                      UART_PutString(string); // Print each parameter
                      UART_CPutString(">\r\n");                 
                }
                
               parameter = atoi(string);  // this is where get error message

   


!E main.c(278): operands of = have illegal types `array 7 of char' and `int'
!E main.c(278): lvalue required
make: *** [obj/main.o] Error 1
 

0 Likes
8 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Look at the string you are giving to atoi(). it should be ascii numeric chars followed by a

   

NULL char to terminate string. If it has non ascii numerics in it, like delimiter chars, then

   

it will choke.

   

 

   

Regards, Dana.

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

You get a compile error which we cannot see from where it is caused. Please attach the complete project. Use Cypress Designer -> File -> Archive Project and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

Thank you for replying.  Its my first time to use forum, do you know how can I attach the project files here?

   

Thanks.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

When you post there is an Add Attachments link below text entry area, you pick that,

   

navigate to where file is, select it, then pick upload link, then click submit when you

   

have finished rest of post.

   

 

   

Regards, Dana..

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

Thank you for the help, I could attach the file now.  

   

Please see the attachment for the UART testing code.

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

The problem is not the string conversion with atoi(), but your try to assign to a char* a value. your line 164 in your file which is flagged as error shows

   

                    offset = rs485_parameter;

   

where offset is declared (line 88) as  char offset[7] = "offset";          //1    

   

and

   

        int rs485_parameter = 0;

   


Which really will not match.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

I see.  I defined the string with same name to the global variable name.  Thank you so much for the help!

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

That was an easy one, so you are always welcome!

   

 

   

Bob

0 Likes