下面程序的功能是从键盘输入一个字符串,编程将其字符顺序颠倒后重新存放,并输出这个字符串。程序的运行结果如下:Input a string:abcdef↙The inversed string is:fedcba按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include #include void Inverse(char *pStr);int main(){ char str[80]; printf("Input a string:\n"); gets(str);//输入字符串 Inverse(str);//将存于str数组中的字符串逆序存放 printf("The inversed string is:\n"); puts(str);//输出字符串 return 0;}void Inverse(char *pStr){ int len = 0; char temp; char *pStart = pStr;//指针变量pStart指向字符串的第一个字符 char *pEnd;//指针变量pEnd指向字符串的最后一个字符 for (; *pStart!='\0'; _________) //求出字符串长度 {len++; } for (pStart=pStr,___________; pStart
A. 第21行: *pStart++第25行: pEnd=pStr+len第27行: *pStart第28行: *pStart = *pEnd
B. 第21行: pStart++第25行: pEnd=pStr+len-1第27行: *pStart第28行: *pStart = *pEnd
C. 第21行: pStart++第25行: pEnd=pStr+len-1第27行: pStart第28行: pStart = pEnd
D. 第21行: *pStart++第25行: pEnd=pStr+len第27行: pStart第28行: pStart = pEnd
Squeeze函数的功能是删除字符串s中所出现的与变量c相同的字符。例如,输入为:abcdef↙c↙输出为:abdef按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include #include void Squeeze(char *s, char c);int main(){ char a[80], c, *s; s = a; gets(a); scanf("%c",&c); Squeeze(s, c); printf("%s\n", s); return 0;}void Squeeze(char *s, char c){ int i, j; for (i = j = 0; s[i] != '\0'; i++) {if (__________){__________;j++;} } _____________; /* 在字符串t2的末尾添加字符串结束标志 */}
A. 第20行:s[i] == c第22行:s[j] = s[i]第26行:s[i] = '\0'
B. 第20行:s[j] != c第22行:s[i] = s[j]第26行:s[j] = '\0'
C. 第20行: s[i] != c第22行: s[j] = s[i]第26行: s[j] = '\0'
D. 第20行:s[j] == c第22行:s[j] = s[i]第26行:s[i] = '\0'
以下程序中函数FindMinString的功能是返回形参指针s1和s2所指字符串中较小字符串的首地址。例如,若运行时依次输入三个字符串:123↙1223↙124↙输出结果为1223按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include #include char *FindMinString( _____________ ){ if(_____________)return(s1); elsereturn(s2);}int main(){ int i; char string[20], str[3][20]; for(i=0;i<3;i++) {gets(str[i]); } strcpy(string,FindMinString(str[0],str[1])); /*对字符串进行复制*/ strcpy(string,___________________); printf("%s\n",string); return 0;}
A. 第3行:char s1, char s2第5行:s1 B. 第3行:char s1, char s2第5行:strcmp(s1,s2)>0第20行:FindMinString(str[0],str[2])
C. 第3行:char *s1, char *s2第5行:s1>s2第20行:strcmp(str[1],str[2])
D. 第3行: char *s1, char *s2第5行:strcmp(s1,s2)<0第20行:FindMinString(string,str[2])
子函数Move的功能是将某字符串中的第i个字符向左移动1位,覆盖第i-1个字符。下面程序通过多次调用Move函数,将字符数组b中存放的字符串依次左移3位,并在移动后的字符串末尾添上字符0补足。程序的运行结果为:234567890034567890004567890000按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include void Move( _________,int i){ a[i-1]=a[i];}int main( ){ char b[11]={"1234567890"}; int i,j; for (j=0;j<=2;j++) {for(i=1;b[i]!='\0';i++){__________;printf("%c",b[i-1]);}_________;printf("%c\n",________); } return 0;}
A. 第2行: char a第15行:Move(b,i)第18行:b[i-1]='\0'第19行:b[i-1]
B. 第2行: char *a第15行: Move(b,i)第18行: b[i-1]='0'第19行: b[i-1]
C. 第2行: char *a第15行:Move(b,i)第18行:b[i]='0'第19行:b[i]
D. 第2行: char a第15行:Move(i,b)第18行:b[i]='\0'第19行:b[i]