I'm trying to store the user input name into the structure. I am using fgets instead of scanf because I want to control the length of the user input. Is it possible to use fgets to store the user input from a single line separated by white space into 2 arrays (for my case it's the lastName[10] and firstName[10])?
Is the only way to use printf function in order to print 2 strings that are taken from the user by firstName and lastName individually?
#include <stdio.h>
#include <string.h>
struct names {
char lastName[10];
char firstName[10];
} names;
int main() {
printf("Enter names (firstName lastName): \n");
fgets(names.firstName, 10, stdin);
fgets(names.lastName, 10, stdin);
printf("first Name: %s last Name: %s \n", names.firstName, names.lastName);
return 0;
}