+ 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

18th Nov 2020, 2:59 PM
Gideon
Gideon - avatar
4 Respostas
+ 4
*q = '\0' it dont look like condition i dont get it.
18th Nov 2020, 3:00 PM
Gideon
Gideon - avatar
+ 4
While(*p != ' ' && *p) //what about this. //help.
19th Nov 2020, 3:50 AM
Gideon
Gideon - avatar
+ 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..
18th Nov 2020, 4:14 PM
Jayakrishna 🇮🇳
+ 3
That mean the value in *p is not a space and a valid value (not null)...
19th Nov 2020, 12:31 PM
Jayakrishna 🇮🇳