niusouti.com

( 14 )以下程序用以删除字符串所有的空格,请填空。#include <stdio.h>main (){ char s[100]={ " Our teacher teach C language! " };int i,j;for ( i=j=0;s[i]!= ’ \0 ’ ;i++ )if ( s[i]!= ‘ ’ ) {s[j]=s[i];j++;}s[j]= 【 14 】printf ( " %s\n " ,s ) ;}

题目

( 14 )以下程序用以删除字符串所有的空格,请填空。

#include <stdio.h>

main ()

{ char s[100]={ " Our teacher teach C language! " };int i,j;

for ( i=j=0;s[i]!= ’ \0 ’ ;i++ )

if ( s[i]!= ‘ ’ ) {s[j]=s[i];j++;}

s[j]= 【 14 】

printf ( " %s\n " ,s ) ;

}


相似考题
更多“( 14 )以下程序用以删除字符串所有的空格,请填空。#include &lt;stdio.h&gt;main (){ char s[100] ”相关问题
  • 第1题:

    请读程序: includde include void fun(char * s) {char a[10]; str

    请读程序: # includde<stdio.h> # include<string.> void fun(char * s) {char a[10]; strcpy(a,"STRING"); s=a; } main() { char*p; fun(p); print{("%s\n",p); } 上面程序的输出结果(表示空格) ( )

    A.STRING

    B.STRING

    C.STRING

    D.不确定的值


    正确答案:D

  • 第2题:

    删除字符串的所有前导空格,请完善程序。 #include <stdio.h> 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; }


    Trim

  • 第3题:

    22、删除字符串的所有前导空格,请完善程序。 #include <stdio.h> 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; }


    C

  • 第4题:

    以下程序用以删除字符串中所有的空格,请填空。

    inculde <stdio.h>

    main()

    { char s[100]=(“our teacher teach c language!”);int I,j;

    For(i=j=0;s[i]!=’’)

    iF(s[i];s[i]!=’\0’) {s[j]=s[i];j ++}

    s[j]=【 】

    printF(“index=%d\n”,s-a);

    }


    正确答案:‘\0’
    ‘\0’ 解析:程序使用变量i遍历字符数组s中的所有字符,使用变量j存放非空格字符。当将所有的非空格字符重新存放到字符数组s中后,应添加字符串结束标志'\0'。

  • 第5题:

    删除字符串的所有前导空格,请完善程序。 #include <stdio.h> void f1(char *s) { char *t; t=________; while(*s==' ') s++; while(*t++=*s++); return; } int main() { char str[80]; gets(str); f1(str); puts(str); return 0; }


    Trim