Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

linked list program using c, but its giving some error which i cant understand please help me to correct this

0 votes
asked May 20, 2018 by annonymus
#include<stdio.h>

#include<string.h>

#include<stdlib.h>

struct list

{ char ISBN[ 20 ];

char NAME[ 20 ];

char AUTHOR[ 20 ];

int YEAR;

char STATUS[20];

struct list *next;

}INFO;

list* getnode(void);

void freenode(list*);

list* addlist(list *,char [],char [] ,char [],int, char[] );

void printlist(list *);

void freelist(list *);

int main()

{

char ISBN[ 20 ];

char NAME[ 20 ];

char AUTHOR[ 20 ];

int YEAR;

char STATUS[20];

list *start;

start=NULL;

for (int i=0;i<10;i++){

printf("Enter book ISBN ");

scanf("%s",&ISBN);

printf("\n Enter book name ");

scanf("%s",&NAME);

printf("\n Enter Author ");

scanf("%s",&AUTHOR);

printf("\n Enter Year");

scanf("%d", &YEAR);

if(YEAR <= 1985){

printf("status is reference");

scanf("%s",&STATUS);

}

else {

printf("status available");

scanf("%s",&STATUS);

}

}

start=addlist(start,ISBN,NAME,AUTHOR,YEAR,STATUS);

}

printlist(start);

freelist(start);

}

list* getnode(void)

{

list *p;

p=(list*)malloc(sizeof(list));

return p;

}

list* addbook(list *p,char ISBN[],char NAME[] ,char AUTHOR[],int YEAR, char STATUS[] );{

list *newElm,*Elm;

newElm=getnode();

strcpy(newElm->ISBN,ISBN);

newElm->NAME=NAME;

newElm->AUTHOR=AUTHOR;

newElm->YEAR=YEAR;

newElm->STATUS=STATUS;

newElm->next=NULL;

if(p==NULL)

return newElm;

else{

Elm=p;

while(Elm->next!=NULL)

Elm=Elm->next;

Elm->next=newElm;

return p;

}

}

void printlist(list *p){

list *q;

q = getnode();

q = p;

do {

printf("%s\t",q->ISBN);

printf("%s\t",q->NAME);

printf("%s\t",q->AUTHOR);

printf("%d\t",q->YEAR);

printf("%s\n",q->STATUS);

q=q->next;

}while(q!=NULL);

}

void freelist(list *p){

list *q,*s;

q=p;

do{

s=q->next;

free(q);

q=s;

}while (s!=NULL);

}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...