I am trying to get a better understanding of c strings I always seem to see myselft missing a big gap everytime I program something I am trying to replace strcat(for a better understanding) The code compiles and runs but I think it hits and infinite loop
Code:
#include <stdio.h>
int main(void){
char fname[256];
char lname[256];
int x=0,y=0;
printf("Enter your first name: ");
fflush(stdout);
fgets(fname,sizeof fname,stdin);
printf("Enter your last name: ");
fflush(stdout);
fgets(lname,sizeof lname,stdin);
while(fname[x]!='\n'){
x++;
}
fname[x]=' ';
x++;
printf("%s\n",fname);
while(lname[y]!='\n'){
fname[x]=lname[y];
}
printf("%s\n",fname);
return 0;
}