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 .

>> gets(p->name);
Bad. Seeing as you're using C++ (noticable only from the *& in insert ), you can use std::getline and std::string s. Also in C++ one does not need to typedef struct s.

>> main() main returns in int: int main() .

Also, good idea not to allow the users to quit.

>scanf("%d",p->id);
p->id isn't a pointer, you need to pass the address of the object rather than the value:

scanf("%d", &p->id);

You also have a second occurrence of that problem in print. Though I have no idea why a print function is taking input. :-/

[edit]
On a side note, your formatting style is atrocious.
[/edit]

thank you so much >
the thing is >>I'm learning (C) ,the only thing that i know about (C++) is I\O functions &(*&) even though i don't know what does it mean.
I know that i'm terrible with pointers so>>>not shacking
any way thanx alottttttt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.