I have this following program:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name[50],fname[50],sname[50],lname[50];
int i,j,k;
printf("First Name:");
gets(fname);
printf("sname:");
gets(sname);
printf("lname:");
gets(lname);
for(i=0;fname[i]!='\0';i++)
name[i]=fname[i];
name[i]=' ';
for(j=0;sname[j]!='\0';j++)
name[i+j+1]=sname[j];
name[i+j+1]=' ';
for(k=0;lname[k]!='\0';k++)
name[i+j+k+2]=lname[k];
name[i+j+k+2]=' ';
printf("Concatenation is %s",name);
}
I'm confused as to why there is a space assigned in name[i]=' '
and name[i+j+1]=' '
and name[i+j+k+2]=' '
in this program.
If I execute with these, then I'm only getting concatenation, but if I remove them, I'm getting only the string of fname
and not a concatenation of all.