I’m reading from a file and need to split a string by null char.
*Buff = "ABC \0 NAME \0 1231 \0 12.32";
Tok = strtok(Buff,'\0');
printf("Tok %s \n", Tok);
This does not work, strtok can not take a null argument.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just use
strlen(the_string) + 1to get the tokens:Example:
The terminating condition is when
Tok >= Buff + sizeof "ABC \0 NAME \0 1231 \0 12.32".