السلام عليكم ورحمة الله وبركاته
اخواني الأعزاء ممكن تساعدوني بهالمشكلة ..
عندي هالمشكلة بهالبرنامج
لما أكبس حرف P بيدخلي معلومات عن STRUCTURE .. رقم وبعدها اسم .. وكل ما اكبس P بيعملي هالحكي ..
ولكن لما أعمل قرائة لهذه السلسلة من الSTRUCTURE عن طريق حرف R .. ما بيقرأ كل السلسلة ...
علما انه بقرأة البرنامج عن طريق الFUNCTION printstack
البرنامج امامكم ... ما هو الحل ؟؟؟؟؟؟
#include<stdio.h>
#include<malloc.h>
#include<string.h>
struct employee
{
int no;
char name[80];
struct employee *next;
};
typedef struct employee node;
node *first,*last,*n;
node *newnode()
{
n=(node*)malloc(sizeof(node));
return(n);
}
void PushNode()
{
n=newnode();
scanf("%d%s",&n->no,&n->name);
if(first==NULL)
first=n;
else{
n->next=first;
first=n;
}
}
void PopNode()
{
printf("Would You Want To Delete First Node(Y/N)");
char select;
scanf("%s",&select);
if(select=='Y')
{
n=first;
first=first->next;
n->next=NULL;
}
}
void PrintStack()
{
n=first;
if(first==NULL)
printf("THE NODE IS EMPTY");
else{
if(n!=last->next){
printf("%d %s\n",n->no,n->name);
n=n->next;
}
printf("%d %s\n",n->no,n->name);
}
}
void main(void)
{
char choice;
printf("Welcome To The Stack Program");
printf("\n\nP Push Node\nO Pop The Stack\n");
printf("R Print The Contnts Of The Stack\nE Exit The Program.");
printf("\n\n\nPlease Make Your Choice:\n");
first=NULL;
scanf("%c",&choice);
while(choice!='E')
{
if((choice=='P')||(choice=='O')||(choice=='R'))
{
if(choice=='P')
PushNode();
else
if(choice=='O')
PopNode();
else
if(choice=='R')
PrintStack();
}
else
printf("Choice Ather Leter\n");
choice=NULL;
scanf("%c",&choice);
}
}