题目中“上面的for 循环语句”为:
for (
i=
0;
i<lim-
1 && (c=getchar()) !=
'\n' && c != EOF; ++
i)
s
[i] = c;
简单的编写了一段程序:
int main(){
char
s[
100];
int lim=
100;
int state=
1;
int i=
0;
char c;
while(
state==
1){
c=getchar();
if( c==
'\n'){
state=
0;
}
else if(c==EOF){
state=
0;
}
else if(i>=lim-
1){
state=
0;
}
s[i++]=c;
}
for(
int j=
0;j<i;++j){
printf(
"%c",
s[j]);
}
return 0;
}
后面添加了两句
for(int
j=
0;
j<
i;++
j)
{
printf("%c",s[j]);
}
为了方便查看结果是否正确,输出结果如下:
转载请注明原文地址: https://www.6miu.com/read-34960.html