Home > Back-end >  ???? The small white for help
???? The small white for help

Time:10-07

Why do you

CodePudding user response:

There is too much code problems, STR should be a two-dimensional array, so as to save five strings,
P incremental calculation is wrong, should increment each time the address of the string
I also didn't give the p value assignment, you sort, so the program exits

CodePudding user response:

reference 1st floor m0_46108109 response:
there is too much code problems, STR should be a two-dimensional array, so as to save five strings,
P incremental calculation is wrong, should increment each time the address of the string
I also didn't give the p value assignment, you can sort, so program out of the

Why the two dimensional array to put five strings

CodePudding user response:

It may be a dimension,
Char STR [20]
Char * s=STR;
for (int i=0; i<20; I + 4)
{
The scanf (" % s ", s);
S=s + 4;
}
So you can save five, each string is 3 characters of the string,
But this is where the vaudeville, or a 2 d is better

CodePudding user response:

reference m0_46108109 reply: 3/f
it may be a dimension,
Char STR [20]
Char * s=STR;
for (int i=0; i<20; I + 4)
{
The scanf (" % s ", s);
S=s + 4;
}
So you can save five, each string is 3 characters of the string,
But this is where the vaudeville, or better with two-dimensional

Why is three strings

CodePudding user response:

Char STR [20], can save 20 characters, if you want to save the five string, each string can only have four characters,
Convenient to handle, the four character position and 3 used to store character, a fourth store \ 0

You should learn to look again, an array of strings, the string is a one-dimensional array, a two-dimensional array to save multiple strings,

CodePudding user response:

reference 5 floor m0_46108109 reply:
char STR [20], can only save 20 characters, if you want to save the five string, each string can only have four characters,
Convenient to handle, the four character position and 3 used to store character, a fourth store \ 0

You should learn to look again, an array of strings, the string is a one-dimensional array, a two-dimensional array to save multiple strings,

Ok, thanks for a great god

CodePudding user response:

So you can save 5 string, this method is the most clear,
 # include & lt; Stdio. H> 
Int main () {
Char STR [4] [20].
For (int I=0; I & lt; 5; I + +)
{
The scanf (" % s ", STR [I]);
}
For (int j=0; J & lt; 5; J++)
{
Printf (" % s \ n ", STR [j]);
}
return 0;
}

CodePudding user response:

Char STR [5] [20]. Here is a 5, write wrong
  • Related