题目内容:
请补充函数proc(),该函数的功能是:把一个字符串中的字符(字母)按从小到大排序,并把这个全部由字母组成的字符串保存在原串中,函数返回这个字符串的长度。例如,若输入“abc12def”,则新字符串为abcdef,字符串长度为6。注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填人所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define M 20
int proc(char*str)
{
int i=0,j=0,k=0,m=0;
char t;
char*p—str;
while(*p)
{
if((*p>='A'&&*p<='Z')||(*p>='a
&&*p<='2'))
【1】 ;
p++;
}
*(str+i)='\0';
【2】 ;
while(*(p+j))
{
k=j;
【3】 ;
while(*(p+k))
{
if(*(p+k)<*(str+m))
{
t=*(str+m);
*(str+m)=*(p+k);
*(p+k)=t;
}
k++;
}
j++;
}
return i;
}
void main()
{
char str[81];
int n;
system("CLS");
printf("Input the original string");
gets(str);
printf("***The Original string***\n");
puts(str);
printf("***The new string***\n");
n=proc(str):
puts(str);
printf("***The length of new string is:
%d***\n",n):
}
参考答案:
答案解析: