【发布时间】:2018-08-07 11:46:47
【问题描述】:
如何在c中创建堆栈,程序不会只输出最后输入的所有字符串 发生了什么?不知道该写什么,但网站要求写一些东西,认为没有任何解释。当我想借助指向下一本书的链接打印所有书籍时,它只输出最后输入的内容。是否覆盖?
#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;
}
【问题讨论】:
-
请举例说明预期行为与实际行为