LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

StrToInt-need a help

Hi..!
 
  I have to conver the string tp the ineger.
  I must display 123. But i am gettting 4367948.
 What am i missing..?
 
unsigned int strl[10];
int str;
char st[10];

   st[0]='1';
   st[1]='2';
   st[2]='3';
   st[3]='\0';

          StrToInt(st,strl);
          printf("%d",strl);
 
Thanx and Regards,
Venki.
 
0 Kudos
Message 1 of 3
(3,361 Views)
Here is a small example of StrToInt. Note that initializing string with "123" is equivalent to setting the individual elements.
 
int value;
char string[10] = "123";
 
StrToInt(string, &value);
 
printf("%d", value);
 
There were two problems with the code you posted.
 
1. You were using strl (essentially a pointer to an unsigned) as the parameter to StrToInt, while it was expecting a pointer to an integer. This would have worked (for positive values) if you had passed *strl to printf, but is still strictly incorrect.
2. You were passing the address of the first element of an unsigned integer to printf when it was expecting an integer value; so, it was actually printing the address of the variable as an integer. If you had passed *strl here instead, you would have seen the output you had expected.
 
Hope this helps,
 
-alex
0 Kudos
Message 2 of 3
(3,352 Views)
thanx alex..it helps me..!
0 Kudos
Message 3 of 3
(3,342 Views)