删除字符串的所有前导空格,请完善程序。 #include void f1(char *s) { char *t; t= ________ ; while(*s==) s++; while(*t++=*s++); } int main( ) { char str[80]; gets(str); f1(str); puts(str); return 0; } 得分/总分
举一反三
- 以下与库函数strcmp(char *s,char *t)功能相等的程序段是( )。? int strcmp3(char *s,char *t){ for ( ; *t==*s; ) { if (!*t) return 0 ; t++ ; s++ ; } return (*s-*t) ;}|int strcmp2(char *s,char *t){ for ( ; *s++==*t++; ) if (!*s) return 0 ; return (*s-*t) ;}|int strcmp1(char *s,char *t){ for ( ; *s++==*t++; ) if (*s=='\0') return 0 ; return (*s-*t) ;}|int strcmp4(char *s,char *t){ for ( ; *s==*t;s++,t++ ) if (!*s) return 0 ; return (*t-*s) ;}
- 分析下程序,写出输出结果。 #include [stdio.h] #include [string.h] void main( ) { char str[]="123456"; int i,x; char t; x=strlen(str)-1; for (i=0;i<=x/2;i++) { t=str[i]; str[i]=str[x-i]; str[x-i]=t; } puts(str); }[/i][/i]
- 以下程序段运行的结果是_____。[br][/br]int fun(char *s)[br][/br]{ char *t=s;[br][/br] while(*t) t++;[br][/br] return (t-s);[br][/br]} void main() { char *str="china"; printf("%d\n",fun(str)); }
- 当运行以下程序时,输入abcd,程序的输出结果是:【1】。#include #include insert(char str[]){int i; i=strlen(str); while(i>0) {str[2*i]=str[i];str[2*i-1]='*';i--;} printf("%s\n",str);}void main(){char str[40]; scanf("%s",str); insert(str);}[/i]
- 以下程序的输出结果是 _[13]_______ . #include #include char *fun(char *t) { char *p=t; return(p+strlen(t)/2); } main() { char *str="abcdefgh"; str=fun(str); puts(str); }