二级C语言高频考点分析与实战
Company Logo Top70 字符串的输入与输出 练习题 1、若准备将字符串“This is a string.”记录下来,错误的输入语句为—— A、scanf(“%20s”,s); B、for(k=0;k17;k++) s[k]=getchar(); C、while((c=getchar())!=‘\n’) s[k++]=c; D、gets(s); A Company Logo Top70 字符串的输入与输出 练习题 2、有以下定义,不能给a数组输入字符串的语句是—— char a[10],*b=a; A、gets(a); B、gets(a[0]); C、gets(a[0]); D、gets(b); B Company Logo Top71 字符串长度函数strlen 例 对于以下字符串,strlen(s)的值为: (1)char s[10]={‘A’,‘\0’,‘B’,‘C’,‘\0’,‘D’}; (2)char s[ ]=“\t\v\\\0will\n”; (3)char s[ ]=“\x69\082\n”; 考点: 字符串长度函数strlen 格式:strlen(字符数组) 功能:计算字符串长度 返值:返回字符串实际长度,不包括‘\0’在内 1 3 1 Company Logo Top71 字符串长度函数strlen 真题分析 (2005年9月)有以下程序,下列说法正确的是— #includestring.h main( ) { char p[ ]={a, b, c},q[10]={ a, b, c}; printf(%d%d\n,strlen(p),strlen(q)); } A、在给p 和q 数组赋初值时,系统会自动添加字符串结束符,故输出的长度都为3 B、由于p 数组中没有字符串结束符,长度不能确定,但q 数组中字符串长度为3 C、由于q 数组中没有字符串结束符,长度不能确定,但p 数组中字符串长度为3 D、由于p 和q 数组中都没有字符串结束符,故长度都不能确定r B Company Logo Top71 字符串长度函数strlen 真题分析 (2005年4月)下列程序中huiwen()函数的功能是检查一个字符串是否是回文,当字符串是回文时,函数返回字符串:yes!,否则函数返回字符串:no!,并在主函数中输出。所谓回文即正向与反向的拼写都一样,例如:adgda。请填空。 #include string.h char*huiwen(char *str) { char *p1,*p2; int i,t=0; p1=str; p2= 【18】; for(i=0;i=strlen(str)/2;i+ +) if(*p1+ +! =*p2--){t=1;break;} if( 【19】) return(yes!); else return(no!); } main( ) { char str[50]; printf(Input:); scanf(%s,str); printf(%s\n, 【20】); } str+(strlen(str)-1) t==0或t!=1或!t 或istrlen(str)/2 huiwen(str) Top71 字符串长度函数strlen 真题分析 (2011年9月)有以下程序 程序运行后的输出结果是_______。(选择题35题) A)654321 B)116611 C)161616 D)123456 Company Logo void fun(char *w, int m) { char s, *p1, *p2; p1=w; p2=w+m-1; while(p1p2) {s=*p1; *p1=*p2; *p2=s; p1++; p2--;} } main() { char a[]=123456; fun(a,strlen(a)); puts(a); } A Company Logo Top71 字符串长度函数strlen 练习题 1、以下程序运行后输入:3,abcde回车,则输出结果是—— main( ) { char s[50];int n,i,z; scanf(“%d,%s”,n,s); z=strlen(s); for(i=1;i=n;i++) move(s,z); printf(“%s”,s); } move(char *str,int n ) { char temp; int i; temp=str[n-1]; for(i=n-1;i0;i--) str[i]=str[i-1]; str[0]=temp; } cdeab Company Logo Top72
原创力文档

文档评论(0)