I am using the code below as part of a bigger program to accept strings of words from the user and analyze them using several other cases. I initially used gets where the program worked as it should but was warned about buffer overflow so am now trying to use fgets. The problem I have below is that I cant get it to display a separate error code for too many characters, it seems too jump to the default error code for the whole switch and ignore the printf in this case. Does anyone know how to get an error here to display and send it back to the options.
Code:case 1: string[MAXSIZE]; printf("\nEnter a string of words:\n\n"); fgets (string, MAXSIZE, stdin); len = strlen(string); if (string[len-1] == '\n') string[--len] = 0; if (string == MAXSIZE) printf("Too many characters please try again"); break;