打印本文 打印本文  关闭窗口 关闭窗口  
06年计算机等级考试二级C程序修改与设计
作者:佚名  文章来源:不详  点击数  更新时间:2008/4/18 14:00:30  文章录入:杜斌  责任编辑:杜斌

给定程序modi1.c中函数 fun 的功能是:将在字符串s中出现、   
 而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字   
 符按原字符串中字符顺序排列,不去掉重复字符。   
 例如:当s = "aabcde",t = "bdfg"时,   
 u中的字符串为"aace"。   
 请改正函数fun中的错误,使它能得出正确的结果。注意:不   
 要改动main函数,不得增行或删行,也不得更改程序的结构!   
 程序 :   
 #include   
 #include   
 #include   
 /************found************/   
 void fun (char *s, char *t, char u)   
 { int i, j, sl, tl;   
 sl = strlen(s); tl = strlen(t);   
 for (i=0; i { for (j=0; j if (s[i] == t[j]) break;   
 /************found************/   
 if (j>tl)   
 *u++ = s[i];   
 }   
 *u = ’\0’;   
 }   
 main()   
 { char s[100], t[100], u[100];   
 clrscr();   
 printf("\nplease enter string s:"); scanf("%s", s);   
 printf("\nplease enter string t:"); scanf("%s", t);   
 fun(s, t, u);   
 printf("the result is: %s\n", u);   
 }   
打印本文 打印本文  关闭窗口 关闭窗口