How to make stack in c, program doesn't output all entered strings only the last what's happening? Don't know what to write but website asks to write something, argues that there isn's any explanations. When I want to print all books with the help of link to their next book, but it's only outputting the last entered thing. Is it overwriting?
#include <stdio.h>
#include <string.h>
typedef struct book book;
struct book{
book *next;
char name[100];
int year;
char author[100];
};
void setter(book *aza, int number){
char name[100];
int year;
char author[100];
scanf("%s", name);
scanf(" %d", &year);
scanf("%s", author);
strcpy( aza->name , name );
aza->year = year;
strcpy( aza->author, author );
number--;
if(number==0){
return;
}else{
setter(&aza->next, number);
}
}
printBooks(book *aza){
if(aza){
printf("%s\n", &aza->name);
printBooks(&aza->next);
}
}
int main()
{
book kitap;
int number;
scanf("%d", &number);
setter(&kitap, number);
printBooks(&kitap);
return 0;
}