HI everybody:
I'm renaad & i'm 21 &student of computer science .
i've a problem & I despairet 4 a help:
l keep having this message "fault access violation at(##) write of address" when I compile my program & i don't know why
this is the code:
(it's a linked list as stack with a choice menu)
#include<stdio.h>
#include<conio.h>
struct student {char name[10];
int id;
struct student *next;
};
typedef struct student record;
int i=0;
void insert (record *&);
void erase (record *&);
void print (record *&);
main()
{int a;
char choice;
record *first;
first=NULL;
do
{
printf("\t\5\5\5\5\tMain Menu\5\5\5\5\5\n");
printf("\t\5\t1-INSERT a student info.\n\t\5\t2-DELETE\n\t\5\t3-DISPLAY the size");
printf("of the list\n\t\5\t4-DISPLAY the LIST\n");
printf("\t\5\5\5Select:\t");
choice=getche();
switch(choice)
{case '1':
insert(first);
do{printf("if you Want 2 insert another student press 1\n");
scanf("%d",&a);
if (a==1)
i++;
insert(first);}while (a==1);
break;
case '2':
printf("The size of the list = %d\n",i+1);
break;}
}while(choice!='5');
getch();
}
void insert (record *&first)
{int a;
record *p;
p=new record;
printf("\nType the student name:\r\n");
gets(p->name);
printf("\nType the ID.\t");
scanf("%d",p->id);
p->next=first;
first=p;
getch();
}
void erase (record *&first)
{record *r;
if (first==NULL)
printf("\nUNDER FLOW\n");
else
{r=first;
first=r->next;
delete r;}
}
void print(record *&first)
{record *m;
m=first;
while(m)
{gets(m->name);
scanf("%d",m->id);}
}
By the way i'm using (Borland C++).
Belive me any suggestion well do.
Thanx for your time .