Code # I thought (C) :
#include
#include
Int main (void)
{
Char * word [100]={" 0 "};//each element for a word (char *)
Char STR [1000]={0};//string
Int str_len=0;
int index=0;
The fgets (STR, 1000, stdin);
Str_len=strlen (STR) - 1;//delete line breaks
for (int i=0; i{
If (STR [I]!=' ')//each word separately stored into a char *
{
* (word [index])=STR [I];
The word [index] + +;
}
The else
{
Index++;
}
}
For (int I=index + 1; I & gt; 0; I -)//reverse output
{
Printf (" % s ", the word [I - 1));
}
system("pause");
return 0;
}
# error:
# hope to get help: how to solve this problem through running? Instead of providing other ideas, problem solving to grow duck after all! Thank you very much!
CodePudding user response:
Char * word [100]={" 0 "};//word for char * pointer array and char * to "0" as constants, immutable,Try the char [10] [100]={0};//note that step size is enough
CodePudding user response:
# include & lt; stdio.h>
#include
Int main (void)
{
//char * word [100]={" 0 "};//each element for a word (char *)
Char * word [100]={NULL};//each element for a word (char *)
Char STR [1000]={0};//string
Int str_len=0, flag=1;
int index=0;
The fgets (STR, 1000, stdin);
Str_len=strlen (STR) - 1;//delete line breaks
STR [str_len]=0;
The word [index]=STR;
for (int i=0; i{
If (STR [I]=='| | STR [I]==' \ n ') {
If (flag)
Index++;
Flag=0;
STR [I]=0;
{} else if (flag==0)
The word [index]=& amp; STR [I];
Flag=1;
}
# if 0
If (STR [I]!=' ')//each word separately stored into a char *
{
//* (word [index])=STR [I];
The word [index]=& amp; STR [I];
//word [index] + +;
}
The else
{
Index++;
}
# endif
}
For (int I=index + 1; I & gt; 0; I -)//reverse output
{
Printf (" % s ", the word [I - 1));
}
Putchar (10);
//system (" pause ");
return 0;
}
For your reference ~