【发布时间】:2016-03-01 06:45:07
【问题描述】:
我被告知要编写一个包含连接函数的程序。该程序应使用fgets (&s1[0], len1+1, stdin) 收集输入字符串
然后将两者相互添加以生产最终产品。
我的问题在于程序编译但它没有在屏幕上显示任何内容,这就是我所拥有的。如果没有这种方法,我看不出如何解决它。
//function to terminate the program incase reach of 0
int str_len (char s[])
{
int i=0;
while (s[i]= NULL)
++i;
return i+1;
}
char string_cat (char*s1, char*s2)
{
//ADDING THE TWO STRINGS
int str_len(char s[])
char *s1 [80]= {'\0'};
char *s2 [40]= {'\0'};
int len1=str_len(s1);
int len2=str_len(s2);
if (int x=0; len1+len2<80; \0;
return;
}
int main ()
{
char string_cat(char*s1,char*s2)
int str_len(char s[])
//RECIVING THE STRINGS TO ADD
char s1 [80];
char s2 [40];
int i=0;
for (i; i !=0; ++i)
{
printf("What is the first sentence?: ")
fgets(*s1[0], 75+1, stdin);
printf("What is the second sentence?:")
fgets(*s2[0],35+1,stdin);
string_cat(*s1,*s2);
printf("The two sentences added together produce the following: %c",s1 )
}
++i
return 0;
}
【问题讨论】:
-
您的代码无法编译。当我尝试编译它时,我得到了很多错误。你用什么编译的?
-
在您的主函数中,您传递变量而不首先声明它。
-
我使用了代码块。也许这就是为什么../编辑:我打开了另一个程序..这就是为什么,我现在得到了错误..回到绘图板
-
如果您希望其他人阅读您的问题,请先编辑它并修正缩进。
标签: c char concatenation fgets