Really confused if my program is behaving the way it's supposed to. this isn't homework, just a fun march madness predictor program I'm writing.
char buffer[20];
char team1_name[20]; // 18 chars + new line + null
char team2_name[20];
printf("Who is team 1?\n");
fgets(buffer, sizeof(buffer), stdin);
strncpy(team1_name, buffer, sizeof(team1_name));
team1_name[strlen(team1_name) - 1] = '\0';
printf("\nWho is team 2?\n");
fgets(buffer, sizeof(buffer), stdin);
strncpy(team2_name, buffer, sizeof(team2_name));
team2_name[strlen(team2_name) - 1] = '\0';
printf("\nEnter %s's info:\n", team1_name);
Out of curiosity I enter a team name greater than 20 characters and it completely skips over the second print statement. am I protecting against buffer overflow? is it up to the user to not put in something huge? Do I need flush statements?
This is the output:
Who is team 1?
wjefowiejfwoiejfweoifjweoifjweofijweoifj
Who is team 2?
Enter wjefowiejfwoiejfwe's info:
Wins in last 12:
Losses in last 12:
Points per game: