I have strange problem where the output of the concatenation comes with a new line between each string input. I tried couple of different things eg. removing the dynamic memory allocation, copying strings into one another and then concatenating. the same issue is there. any ideas why?
Input:
> one
> two
Output:
> Result of concatenation: one
> two
here is the code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
/* code */
char string1[100];
char string2[100];
char *concat;
fgets(string1,100,stdin);
fgets(string2,100,stdin);
unsigned int size = strlen(string1) + strlen(string2);
concat = (char *) malloc(sizeof(char) * size);
if (concat==NULL)
{
exit(0);
}
strcat(concat,string1);
strcat(concat,string2);
printf("Result of concatenation: %s",concat);
return 0;
}