+ 3
Help me with this code.
#include <iostream> #include <cstdio> using namespace std; int main() { char str[80]; char token[80]; char *p; char * q; cout << "enter a sentence: "; gets(str); p = str;// address of str to p while(*p) { q = token;// address of token to q while(*p != ' ' && *p)//explain this { *q = *p;//values of p to q q++; p++; } if(*p) p++; *q = '\0'; //explain this cout << token << endl; } } https://code.sololearn.com/cfj22PS4v4n3/?ref=app https://code.sololearn.com/cfj22PS4v4n3/?ref=app
4 Respuestas
+ 4
*q = '\0' it dont look like condition i dont get it.
+ 4
While(*p != ' ' && *p)
//what about this.
//help.
+ 3
If you don't add then you may get garbage values and or infinite loop... It is about saying end of string value to compiler..
+ 3
That mean the value in *p is not a space and a valid value (not null)...