I'm having trouble adding a "0" string to a list of strings in C.
With my current code, I'm having trouble distinguishing between a NULL value and a "0" with my current code. I have tried to debug with the if statement (if(pch == "0")) but when I'm outputting it doesn't go into the if statement.
printf("%c\n",next_line[0]);
pch = strtok(next_line,",");
printf("%s\n",pch);
if(pch == "0"){
printf("NULL VALUE");
strcpy(strs[i],pch);
i++;
pch = strtok(NULL, ",");
}
while(pch != NULL){
strcpy(strs[i],pch);
i++;
pch = strtok(NULL, ",");
}
//go on to print values
the input is: 0,1,03:48:13,9
I never make it past the first character. What can I do to keep my code? Can I maybe change
pch = strtok(NULL, ",");
to pch = strtok(SOMEOTHERVALUE, ",");?
nullorzero?NULLin C) work fine.==do? It tells you if two things are equal. What ispch? It's a pointer to a part of the line. What is"0"? It's a pointer to a constant string "0". What happens when you compare pointers with==?