假定输入的字符串中只包含字母和*号。请编写函数proc(),它的功能是:只删除字符串前导和尾部的*号,串中字母之间的*号都不删除。形参m给出了字符串的长度,形参h给出了字符串中前导*号的个数,形参e给出了字符串中最后*号的个数。在编写函数时,不得使用c语言提供的字符串函数。 例如,若字符串中的内容为****a*bc*def*g*******,删除后,字符串中的内容则应当是a*bc*def*g。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容。 试题程序: #include<stdio.h> #include<conio.h> void proc(char*a, int m, int h, int e)
void main()
char s[81], *t, *f; int m=0, tn=0, fn=0; printf("Enter a string: \n"); gets(s); t=f=s; while(*t) t++; m++; ) //m为字符串的长度 t--; //指针t指向字符串尾部 while(*t==’*’) t--; tn++; //指针t指向最后一个字母,tn统计尾部’*’的个数 while(*f==’*’) f++; fn++; //指针f指向第一个字母,tn统计前导’*’的个数 proc(s, m, fn, tn); printf("The string after deleted: \n"); puts(s); )
【参考答案】
void proc(char * a, int m, int h, int e) { int i,......