|
10鱼币
我是用VS2017,为什么使用scanf存不进去数据,麻烦大佬们帮忙看看
#include <stdio.h>
#include <stdlib.h>
struct Book
{
char title[128];
char author[40];
struct Book *next;
};
void getInput(struct Book *book);
void addBook(struct Book **library);
void printLibrary(struct Book *library);
void getInput(struct Book *book)
{
printf("请输入书名:");
scanf_s("%s", book->title);//这里
printf("请输入作者:");
scanf_s("%s", book->author);//和这里
}
void addBook(struct Book **library)
{
struct Book *book, *temp;
book = (struct Book *)malloc(sizeof(struct Book));
if (book == NULL)
{
printf("内存分配失败了!\n");
exit(1);
}
getInput(book);
if (*library != NULL)
{
temp = *library;
*library = book;
book->next = temp;
}
else
{
*library = book;
book->next = NULL;
}
}
void printLibrary(struct Book *library)
{
struct Book *book;
int count = 1;
book = library;
while (book != NULL)
{
printf("Book%d: ", count);
printf("书名: %s\n", &book->title);
printf("作者: %s\n", &book->author);
book = book->next;
count++;
}
}
int main(void)
{
struct Book *library = NULL;
int ch;
while (1)
{
printf("请问是否需要录入书籍信息(Y/N):");
do
{
ch = getchar();
} while (ch != 'Y' && ch != 'N');
if (ch == 'Y')
{
addBook(&library);
}
else
{
break;
}
}
printf("请问是否需要打印图书信息(Y/N):");
do
{
ch = getchar();
} while (ch != 'Y' && ch != 'N');
if (ch == 'Y')
{
printLibrary(library);
}
return 0;
}
用了 微软的发明,你在跨平台开发的时候会比较头疼
你需要把你写的代码中的所有 _s 去掉
但是你又必须在 微软的环境再加上 _s
|
最佳答案
查看完整内容
用了 微软的发明,你在跨平台开发的时候会比较头疼
你需要把你写的代码中的所有 _s 去掉
但是你又必须在 微软的环境再加上 _s
|