a = {49, .....}???Originally posted by QuestionC
Okay, let's say this is the program...The 0 is very important, as atoi is meant for reading a 0 terminated character string. That is to say, if instead I used a[3] = {49, 50, 51}, then atoi(a) would have just kept reading for integer values in the memory past a[3] because it hadn't yet encounted the string terminator... '\0'.Code:#include <stdlib.h> main () { char a[4]; int i; a = {49, 50, 51, 0}; // 49 = '1', 50 = '2', 51 = '3', 0 = '\0' // So a is the string "123" i = atoi (a) // Now i is the integer value 123 return; }
you try to compile this?
probably not!
any way this is not the meaning of atoi(ascii to integer),
void main(void)
{
char *a;
a = "49";
printf("%d",atoi(a));
}
output:
49 press any key to continue...