Home > Back-end >  The output character array behind why there are garbled? Request a great god for help
The output character array behind why there are garbled? Request a great god for help

Time:09-30

#include
#include
#include
20 # define N
Int main (int arg c, char * argv [])
{
Char s [N].
Char a, [N].
int i;
Int t=0;
Int j=0;
Int max1=0;
Int Max=0;
While (t<5)
{
printf("\n");
Printf (" input the first line % d: ", t + 1);
For (I=0, j=0; [I] (s=getchar ())!='\ n'; I++)
{
j++;
}
S [I]='\ 0';
If (j> Max)
{
Max=j;
Max1=t;
for(j=0; S [j].='\ 0'; J++)
{
A [j]=s [j];
S [j]='\ 0';
}
}
t++;
}
printf("\n");
Printf (" is the longest line length is % d % d: content is: ", max1 + 1, Max).
for(i=0; A [I]!='\ 0'; I++)
{
Printf (" % c ", a [I]);
}
printf("\n");
return 0;
}

CodePudding user response:

for(j=0; S [j].='\ 0'; J++)//string terminator has not been assigned to a, because the s [j]=='\ 0' exit for the
{
A [j]=s [j];
S [j]='\ 0';
}
A [j]='\ 0';//so here to add a string terminator
  • Related