2级C语言填空

来源:百度知道 编辑:UC知道 时间:2024/05/22 09:13:13
给定程序的功能是将在字符串s中出现、而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。
例如:当s="112345",t="2467"时,u中的字符串为"1135"。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

#include <stdio.h>
#include <string.h>

void fun (char *s,char *t, char *u)
{ int i, j, sl, tl;
sl = strlen(s); tl = strlen(t);
for (i=0; i<sl; i++)
{ for (j=0; j<tl; j++)
/************found************/
if (s[i] == t[j]) ___1___ ;
if (j>=tl)
/************found************/
*u++ = ___2___;
}
/************found************/
___3___ = '\0';
}

main()
{ char s[100], t[100], u[100];
printf("\nPlease enter string s:"); scanf("%s", s);
printf("\nPlease enter string t:"); scanf("%s", t);
fun(s, t, u);
printf("the result is: %

#include <stdio.h>
#include <string.h>

void fun (char *s,char *t, char *u)
{ int i, j, sl, tl;
sl = strlen(s); tl = strlen(t);
for (i=0; i<sl; i++)
{ for (j=0; j<tl; j++)
if (s[i] == t[j]) break ;
if (j>=tl)
*u++ = s[i];
}
*u= '\0';
}

main()
{ char s[100], t[100], u[100];
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);
}