哪些基金包含中药股票:一个程序搞不定,大家帮忙看看

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/20 20:05:37
#include<stdio.h>
#include<string.h>
char func(char s[],char t[])
{
int i,j,n,a,b;
char u[100];
n=strlen(s);
for(i=0;s[i]!='\0';i++)
{
a=0,b=0;
for(j=0;t[j]!='\0';j++)
{
if(s[i]==t[j])
a++;
}
if(a==0)
{
u[b]=s[i];
b++;
}
}
u[b]='\0';
return(*u);
}
void main()
{
char s[100],t[100],u[100];
printf("input the first words:\n");
scanf("%s",&s);
printf("input the other words:\n");
scanf("%s",&t);
printf("%s,%s\n",s,t);
*u=func(s,t);
printf("%s",u);
}
题目
编一函数 fun 的功能是:将在字符串s中出现、而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。
例如:当s = "AABCDE",t = "BDFG"时,
u中的字符串为"AACE
结果出不来。

按楼主的思路来写(二楼的取巧了,函数不返回值,借用地址传递把U传过来)

#include<stdio.h>
#include<string.h>
char *func(char s[],char t[])
{
int i,j,n,a,b;
char u[100];
n=strlen(s);
b=0;
for(i=0;s[i]!='\0';i++)
{
a=0;
for(j=0;t[j]!='\0';j++)
{
if(s[i]==t[j])
a++;
}
if(a==0)
{
u[b]=s[i];
b++;
}
}
u[b]='\0';
return u;
}
void main()
{
char s[100],t[100],*u;
printf("input the first words:\n");
scanf("%s",&s);
printf("input the other words:\n");
scanf("%s",&t);
printf("%s,%s\n",s,t);
u=func(s,t);
printf("%s",u);
}

你的最错误的地方是:
char u[100];
n=strlen(s);
for(i=0;s[i]!='\0';i++)
{
a=0,b=0;
这里让b不停地为0,你后面的b++失去意义,使得一直在U串中第一位填值。
第2就是函数只能返回一个值,所以只能返回地址,所以在函数定义是少个*。
第3,你返回的return(*U)的意思何在呢。

#include<stdio.h>
#include<string.h>
void func(char s[],char t[],char u[])
{
int i,j,n,a,b;
n=strlen(s);
b=0;
for(i=0;s[i]!='\0';i++)
{
a=0;
for(j=0;t[j]!='\0';j++)
{
if(s[i]==t[j])
a++;
}
if(a==0)
{
u[b]=s[i];
b++;
}
}
u[b]='\0';
}
void main()
{
char s[100],t[100],u[100];
printf("input the first words:\n");
scanf("%s",&s);
printf("input the other words:\n");
scanf("%s",&t);
printf("%s,%s\n",s,t);
func(s,t,u);
printf("%s",u);
}

和2楼的差不多,不跟了
同意2楼意见

对不起,答错了,删!