建议编写一个程序来连接两个字符串 [英] suggestion for writing a program to concatanate two strings

查看:55
本文介绍了建议编写一个程序来连接两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我已经编写了一个程序来连接两个字符串,并且应该将

返回给主程序。我附上代码,

请给我评论。谢谢,

main()

{

char s1 [20],s2 [20];

printf (输入第一个字符串);

scanf("%s",s1);

printf("输入第二个字符串");

scanf("%s",s2);

string_concatenate(& s1,& s2);

}

count_characters(char * x)

{

int i = 0,count = 0;

for(i = 0; *(x + i)!=''\'''; i ++)

count ++;

返回计数;

}

string_concatenate(char * s1,char * s2)

{

int i,j;

char s3 [50];

for(i = 0; i< count_characters(s1); i ++)

s3 [i] = s1 [i];

for( j = 0; j< count_characters(s2); j ++)

s3 [i + j] = s2 [j];

s3 [i + j] = s2 [ j];

printf("%s",s3);

}

解决方案
>您好,

我已经编写了一个程序来连接两个字符串,并且应该将
返回给主程序。我附上代码,
请给我评论。谢谢,




你不是王子,请不要像他一样写 - 你把它拉下来

非常糟糕。


另外,你的string_concatenate没有返回主程序,它会打印出结果。事实上它根本不会返回任何东西。


对不起,

i知道这很傻。

但是我想在主程序中打印它。

i希望将数组返回到主使用地址

你可以改变我的代码我指针很差所以我正在练习


sr ***** **@gmail.com 写道:

对不起,
我知道这很傻。
但我想在主程序中打印它。
我想将数组返回到主使用地址
你可以改变我的代码我指针很差所以我在练习




请阅读< ; HTTP://cfaj.freeshell.org/google/>并遵循它的建议。


请不要使用像u这样的愚蠢缩写词。对于你和q对于

问题。它只会让你的文章更难阅读。并且

请使用适当的大写字母(I,而不是i,以及第一个字母

的句子)。


我不是说这是挑剔的;这将使我们更容易帮助你



-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Hello,
I have written a program to concatanae two strings, and should be
returned to the main program. Iam enclosing the code,
please give me ur critics. Thanks,
main()
{
char s1[20],s2[20];
printf("enter first string");
scanf("%s",s1);
printf("enter second string");
scanf("%s",s2);
string_concatenate(&s1,&s2);
}
count_characters(char *x)
{
int i=0, count=0;
for(i=0;*(x+i)!=''\0'';i++)
count++;
return count;
}
string_concatenate(char *s1,char *s2)
{
int i,j;
char s3[50];
for(i=0;i<count_characters(s1);i++)
s3[i]=s1[i];
for(j=0;j<count_characters(s2);j++)
s3[i+j]=s2[j];
s3[i+j]=s2[j];
printf("%s",s3);
}

解决方案

> Hello,

I have written a program to concatanae two strings, and should be
returned to the main program. Iam enclosing the code,
please give me ur critics. Thanks,



You are not Prince, please don''t write like him - you pull it off
badly.

Also, your string_concatenate doesn''t "return to the main program", it
prints its result. It in fact does not return anything at all.


i am sorry,
i know it is silly q.
but i want to print it in main program.
i want to return the array to main using address
can u change my code i am poor in pointers so i am practicing


sr*******@gmail.com writes:

i am sorry,
i know it is silly q.
but i want to print it in main program.
i want to return the array to main using address
can u change my code i am poor in pointers so i am practicing



Please read <http://cfaj.freeshell.org/google/> and follow its advice.

Please don''t use silly abbreviations like "u" for "you" and "q" for
"question". It just makes your article more difficult to read. And
please use proper capitalization ("I", not "i", and the first letter
of a sentence).

I''m not saying this to be picky; it will make it easier for us to help
you.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于建议编写一个程序来连接两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆