الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

linked list

مغلق
بدأه ABDULLAH1003 في 30 أبريل 2003 · 5 رد · 791 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا البرنامج يقراء ويخزن في الlinked list القراءه صحيحه بس المشكله انه ما يطبع ارجو منكم تصححيح الخطأ وشكرا

#include
#include
#include
typedef struct node{
	char bookn[20];
	char bookw[20];
    int snumber;
    struct node *link;
}node;
typedef struct list{
	node *head;
}list;

void create(list*);
void add_node(list*,node*,node*);
void add_data(list*);
void print_list(list);
void main()
{
  list l;
  create(&l);
  add_data(&l);
  print_list(l);
}
/***********************/
void create(list*l){
	l->head=NULL;
}

/********/
void add_node(list*l,node*pred,node*pnew)
{

	if(pred==NULL){
		pnew->link=l->head;
		l->head=pnew;
	}
	else{
		pnew->link=pred->link;
		pred->link=pnew;
	}
}
/**************************/
void add_data(list*l){

node *pnew,*pred=NULL,*ploc;

    pnew=(node*)malloc( sizeof(node) );
	printf("Enter the name of the book:");
    scanf("%s",pnew->bookn);
	while( strcmp(pnew->bookn ,"$")){ 
	printf("Enter the name of the man who write the book:");
	scanf("%s",pnew->bookw);
	printf("Enter the serual number of the book:");
	scanf("%d",&pnew->snumber);

    add_node(l,pred,pnew);
    printf("nEnter the name of the book:");
    scanf("%s",pnew->bookn);
	}
}
/************************/
void print_list(list l)
{
	node *p;
	p=l.head;
	while(p!=NULL){
		printf("book name is %sn",(p->bookn));
		printf("other name is %sn",(p->bookw));
		printf("serial number is %dn",(p->snumber));
        printf("*************************************");
		p=p->link;
	}
}

/************************/
#2

هل يدخل ضمن حلقة while عندما تعطيه أمر الطباعة , إن كان الجواب لا فهذا يعني أنك تمرر له list فارغة , أنصحك باستعمال الكلمة Next بدلاً من الكلمة link

#3

اخوي ممكن تصحح الكود

:cool::cool:

#4

your error was in the Function

/*
void add_node(list*l,node*pnew)
print_list(list* l)
add_data
*/

the Correct code

#include
#include
#include
#include

typedef struct node{
    char bookn[20];
    char bookw[20];
    int snumber;
    struct node *link;
}node;
typedef struct list{
    node *head;
}list;

void create(list*);
void add_node(list*,node*);
void add_data(list*);
void print_list(list*);
void main()
{
  list l;
  create(&l);
  add_data(&l);
  print_list(&l);
}
/***********************/
void create(list*l){
    l->head=NULL;
}

/********/
/* this function is changed*/
void add_node(list*l,node*pnew)
{

     if(l->head==NULL){
        pnew->link=NULL;

        l->head=pnew;
    }
    else{
        pnew->link=l->head;
        l->head=pnew;
    }

}
/**************************/
/* this function is changed*/
void add_data(list*l){

node *pnew=NULL,*ploc;

    char ss[20];
    printf("Enter the name of the book:");
	scanf("%s",ss);
    while( strcmp(ss ,"$")){ 
    pnew=(node*)malloc( sizeof(node));
	strcpy(pnew->bookn,ss);

		printf("Enter the name of the man who write the book:");
    scanf("%s",pnew->bookw);
    printf("Enter the serual number of the book:");
    scanf("%d",&pnew->snumber);

    add_node(l,pnew);
    printf("nEnter the name of the book:");
    scanf("%s",ss);
    }
}
/************************/

/* this function is changed*/
void print_list(list* l)
{
    node *p;
    p=l->head;
    while(p!=NULL){
        printf("book name is %sn",(p->bookn));
        printf("other name is %sn",(p->bookw));
        printf("serial number is %dn",(p->snumber));
        printf("n*************************************n");
        p=p->link;
    }
}
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#5

اريد ان اعرف ما نوعية البيانات التي تظهر لك هل هي بيانات لها علاقة بالموضوع ام لا

#6

;););)مشكور يااخوي وما قصرت

هذا الموضوع مغلق.

مواضيع مشابهة