A little question someone might be able to help with regarding parsing strings.
ive got a little function that takes a string in the format of a phone number, a space, and a first name.
char buffer = "12345678 john".
i need to break the string into the number and the name.
the code i have which does that, and converts the number into an int is
char buffer = "123456 bob"
char *num, *name;
num = strtok(buffer," ");
name = strtok(NULL," ");
number = atoi(num);
so i do a simple:
printf("Phone number is: %d name is %s", number, name)
to just check that it has actually been split into the 2 parts correctly. and sure enough, i get output like:
"phone number is 123456 name is bob".
BUT... if im passing 'buffer' into the function as a parameter i get problems.
my code is exactly the same except instead of declaring buffer to = '123456 bob' inside the function like the code above, im passing it in. EG
void parseFunc (char buffer)
thats the only change in the code, yet when i run this version the output i get is:
"phone number is 123456 name is (null)".
what am i doing wrong? why do i get a 'null" value when i parse a string thats been passed in, and not when i declare a string within the function?
any help would be much appreciated! Thanks