I was told to write a program containing a concatenate function. This program should collect the input strings using fgets "(&s1[0], len1+1, stdin)"and then add the two to each other to produce a final product.
My problem falls in that the program compiles but it doesn't display anything on the screen whatsoever, here's what I've got. I couldn't see how I could get it solved without this method of approach.
Code:
#include <stdio.h>
#include <string.h>
//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= (int)str_len(&s1);
int len2= (int) str_len(&s2);
char *strcat (s1, s2);
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;
printf("What is the first sentence?: ")
fgets(*s1[0], 35+1, stdin);
printf("What is the second sentence?:")
fgets(*s2[0],75+1,stdin);
if (int i=0; len1+len2<80; ++i)
{
string_cat(*s1,*s2);
else
printf (“Sorry, too long of a sentence”);
}
printf("The two sentences added together produce the following: %c",s1[] )
++i
return null;
}
|