请补充main函数,该函数的功能是:把字符串str中的字符向前移动一位,原来的第一个字符移动到字符串尾,结果仍然保存在原字符串中。 例如,输入“how do you do?”,则结果输出“ow do you do?h”。 注意:部分源程序给出如

admin2010-05-05  30

问题 请补充main函数,该函数的功能是:把字符串str中的字符向前移动一位,原来的第一个字符移动到字符串尾,结果仍然保存在原字符串中。
   例如,输入“how do you do?”,则结果输出“ow do you do?h”。
   注意:部分源程序给出如下。
   请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
   试题程序:
   #include <stdio. h>
   #define N 80
   main()
   {
        char str[N], ch;
        int i;
        clrscr ();
        printf("\n Input a string:In");
        gets (str);
        printf("\n*** original string ***In");
        puts (str);
        ch=str [0];
        for (i=0;【  】; i++)
              str =str [i+1];
                【  】;
       printf("\n *** new string ***\n");
       puts (str);
   }

选项

答案str[i+1 str[i]=ch

解析 第一空:for循环的条件是要移动的字符不为’0’,即还没有到字符串的最后一个字符。第二空:ch中保存了字符串的第一个字符,按题目要求移动到字符串尾,而str是’\0’的前一个字符,也就是字符串尾,故将ch赋给str
转载请注明原文地址:https://kaotiyun.com/show/wHID777K
0

相关试题推荐
最新回复(0)