The question is to input one string per line (<10 for each) include whitespace possibly and put the first n chars of the second string behind of the first string. And I tried many times using different input function and there are differences between them. I wonder why ? Input like this:
hello
c world
3
Wanted: helloc w
#include<string.h>
void fun(char *s1, char *s2, int n) {
int l = strlen(s1);
for(int i=0;i<n;i++) {
s1[l+i]=s2[i];
}
int m=strlen(s1);
s1[m]='\0'; //It doesnot work.Because when it is not here the outcome is the same.Both `fgets` and `gets`
}
int main()
{ char s1[10];char s2[8]; int n;
gets(s1);
gets(s2);
scanf("%d",&n);
fun(s1,s2,n);
printf("%s",s1);
return 0; //This is the only one output right.
}
BUt if
char s2[10];//output is :helloc w?@ What is different,why the length of string influence the output.
if
char s2[8];
fgets(s1,10,stdin);
fgets(s2,8,stdin);
//output:
hello
c w
why fgets influence the format of output