I'm able to get it into the while statment and it shows the options. But i keep gettign a referance window in dos when i hit one of the options what did i do wrong.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define FLASE 0
#define TRUE 1
#define Nlen 25
typedef struct person{
char FName [Nlen +1];
char LName [Nlen +1];
char Sex;
char Grade;
struct person *Next;
} PERSON;
void PrintList (PERSON*);
int DeletePerson;
PERSON* InsertNode (PERSON*, PERSON*);
main ()
{
PERSON *STU; //TEmp pointer used to creat list
int Ans; //User responce
int Len, //Name Length
Deleted; //True if requested item deleted
char FName [Nlen +1]; // first name
char LName [Nlen +1]; // lase name
char Grade, Sex, Ans1;
FILE *fin;
PERSON *TOP = NULL; //Initialize top list point to Null
fin = fopen( "e:data.txt", "rw");
while (fscanf(fin, "%25s %25s %c %c\n", Nlen, STU->LName, STU->FName, STU->Sex,STU->Grade) == EOF){
{
printf ("chose option you want to do\n");
printf ("Option 1 : Enter New Recode\n");
printf ("Option 2 : Display List\n");
printf ("Option 3 : Quit\n");
scanf ("%d", Ans);
switch(Ans){
case '1' :
STU = (PERSON*) malloc (sizeof (PERSON));
if (STU == NULL)
printf ("Error -- could not allocate memory\n\n");
else {
printf ("\nEnter students first name ( uo to %d letters):", Nlen);
fgets (STU->FName, Nlen+1, stdin);
Len = strlen (STU->FName);
if (STU->FName[Len-1]== '\n')
STU->FName [Len-1] == '\0';
printf ("\nEnter students first name ( uo to %d letters):", Nlen);
fgets (STU->LName, Nlen+1, stdin);
Len = strlen (STU->LName);
if (STU->LName[Len-1]== '\n')
STU->LName [Len-1] = '\0';
printf ("Please enter Sex");
scanf ("%c", &STU->Sex);
printf ("Please enter Grade");
scanf ("%c", &STU->Grade);
STU->Next= NULL;
break;
} //else statment end
case '2' :
fscanf(fin, "%25s %25s %c %c\n", Nlen, STU->LName, STU->FName, &STU->Sex, &STU->Grade);
printf ("%s %s %c %c\n", LName, FName, Sex, Grade);
break;
case '3' :
printf ("you chose to exit. Hit enter to close");
break;
}//end of switch
} // end of while
}
getchar ();
getchar ();
return 0;
}