# include & lt; stdio.h>
Int main (void)
{
Char s [100];
Int I, n=0;
The scanf (" % s ", s);
For (I=0;; I++)
{
If (s [I]!=' '& amp; & S [I]! )
='. 'n++;
The else {
Printf (" % d ", n);
N=0;
If (s [I]! )
='. 'Printf (" ");
The else
break;
}
}
return 0;
}
CodePudding user response:
Reference:# include & lt; stdio.h>
Int main (void)
{
Char s [100];
Int I, n=0;
//the scanf (" % s ", s);//the scanf () in space, the input end,
Gets (s);
For (I=0;; I++)
{
If (s [I]!=' '& amp; & S [I]! )
='. 'n++;
The else {
Printf (" % d ", n);
N=0;
If (s [I]! )
='. 'Printf (" ");
The else
break;
}
}
return 0;
}
//it 's great to see you here.
//5 2, 3, 4, 3, 4, please press any key to continue...
CodePudding user response:
The scanf Spaces will be quit, thus lead to can't find the for '. 'and' software in an infinite loop,Can make the following changes:
#include
Int main (void)
{
Char s [100];
Int I, n=0;
//the scanf (" % s ", s);
The scanf (" % [^.] ", s);//testing met 'after exit,
For (I=0;; I++)
{
If (s [I]!=' '& amp; & S [I]!=NULL)
n++;
The else {
Printf (" % d ", n);
N=0;
If (s [I]!=NULL)
Printf (" ");
The else
break;
}
}
return 0;
}
CodePudding user response:
Error 1: char s [100]; Uninitialized '\ 0', so what is stored inside things who also don't knowError 2: the scanf (" % s ", s); Xyz meet space ends, so your hi. Only read hi, and xyz. Still in the cache of
Mistake 3: the for (I=0;; I++) you end of this period can only be random, the place you exit is s [I]!=' 'and'. ', in fact, due to the wrong 1, what is stored inside don't know, do you think of out of place there is a big problem actually,
Don't directly provide the answer, can think about these places