給定程序modi1.c中函數(shù) fun 的功能是:將未在字符串s中出
現(xiàn)而在字符串t中出現(xiàn)的字符形成一個新的字符串放在u中,u中字
符按原字符串中字符順序排列,不去掉重復(fù)字符。
例如,當s = "abcde",t = "bdfgg"時,
u中的字符串為"fgg"。
請改正函數(shù)fun中的錯誤,使它能得出正確的結(jié)果。注意:不
要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
程序 :
#include
#include
#include
void fun (char *s, char *t, char *u)
{ int i, j, sl, tl;
sl = strlen(s); tl = strlen(t);
/************found************/
for (i=0; i/************found************/
{ for (j=0; j if (t[i] == s[j]) break;
if (j=sl) *u++ = t[i];
}
/************found************/
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);
}
現(xiàn)而在字符串t中出現(xiàn)的字符形成一個新的字符串放在u中,u中字
符按原字符串中字符順序排列,不去掉重復(fù)字符。
例如,當s = "abcde",t = "bdfgg"時,
u中的字符串為"fgg"。
請改正函數(shù)fun中的錯誤,使它能得出正確的結(jié)果。注意:不
要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
程序 :
#include
#include
#include
void fun (char *s, char *t, char *u)
{ int i, j, sl, tl;
sl = strlen(s); tl = strlen(t);
/************found************/
for (i=0; i/************found************/
{ for (j=0; j if (t[i] == s[j]) break;
if (j=sl) *u++ = t[i];
}
/************found************/
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);
}