I made a program which accepts strings (first/last names) but instead of a typical output of
Phil Snowken age 3 , i am getting
Phil
Snowken
age 3
fgets()
reads newlines with the string entered, so each time you press enter it gets the \n
also read into string (see man fgets)
You have to check the last character and if it's \n
change it to \0
, like that:
size_t length = strlen(base[i].fname);
if (base[i].fname[length-1] == '\n')
base[i].fname[length-1] = '\0';