假设用户输入的是Go west, young man!,下面各程序的输出是什么(在ASCII码中,!紧跟在空格字符后面)
#include<stdio.h>
int main(){
char ch;
scanf("%c",&ch);
while(ch!='g')
{
printf("%c",ch);
scanf("%c",&ch);
}
return 0; /* Go west, youn */
}
#include<stdio.h>
int main(){
char ch;
do{
scanf("%c",&ch);
printf("%c",ch);
}while(ch != 'g');
return 0; /* Go west, young */
}
#include<stdio.h>
int main(){
char ch;
scanf("%c",&ch);
while(ch!='g'){
printf("%c",++ch);
scanf("%c",&ch);
}
return 0; /* Hp!xftu-!zpvo */
}
#include<stdio.h>
int main(){
char ch;
scanf("%c",&ch);
for(ch='$';ch!='g';scanf("%c",&ch))
printf("%c",ch);
return 0;
}
/* $o west, youn
* 用户使用for循环将ch初始化为'$',
* 因此for循环前的scanf() 函数读取结果被覆盖
*/