Here's the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* struct student -- the basis for the student data */
struct student {
char name[50]; /* holds the name of the student */
struct grades *grade_list; /* the student's grade list */
struct list *next_student; /* pointer to next student */
};
/* struct grades -- the list of grades per student */
struct grades {
int grade; /* the actual grade for this struct */
struct grades *next_grade;
};
/* enums -- the menu item chosen */
enum menu_opts {SRCHSTUD, ADDSTUD, EXIT, ERROR};
int printmnu()
{
char line[2];
/* display menu items for user input */
printf("***********************--MENU--************************\n");
printf("-Search Student(S)\t-Add Student(A)\t\t-Exit(E)\n");
/* user input */
printf("Choice: ");
fgets(line, sizeof(line), stdin);
strcpy(line, strupr(line));
/* figure out what user chose and return enum-ed value */
if (line[0] == 'S')
{return SRCHSTUD;}
else if (line[0] == 'E')
{return EXIT;}
else if (line[0] == 'A')
{return ADDSTUD;}
else
{return ERROR;}
}
int main()
{
int test;
char strline[10];
test = printmnu();
/* Check user input and take appropriate actions */
if (test == EXIT)
{
printf("Exit (Yes/No): ");
fgets(strline, sizeof(strline), stdin);
}
return 0;
}
My problem is this. This code compiles fine (it is an unfinished program). Right now, it only gets input from the user. But, the first fgets works fine and gets a string from the user. When the function returns back to main, and if "test" == EXIT, I can't get a string from the user. I know it reached that code because it did print "Exit (Yes/No): ", but it just ended the program there. Why didn't it get the string the second time with fgets? If it at all matters, I'm using VC++6. If you have time, try to compile it and tell me the results. Thanks...
--Garfield