m0_59064287 2021-06-06 20:12 采纳率: 100%
浏览 62
已采纳

求大神指点,为什么这段代码运行后,才输入一个,就显示”请按任意键继续“,不能再输入了

#include<stdio.h>

struct Date
{
	int year;
	int month;
	int day;
};
struct Book
{
	char title[128];
	char author[40];
	char price;
	struct Date date;
	char publisher;
};
struct Book getinput(struct Book book)
{
	printf("书名:");
	scanf_s("%s", book.title);
	printf("作者:");
	scanf_s("%s", book.author);
	printf("价格:");
	scanf_s("%f", book.price);
	printf("出版日期:");
	scanf_s("%d-%d-%d", book.date.year,book.date.month,book.date.day);
	printf("出版社:");
	scanf_s("%s", book.publisher);
	return book;
}
void printBook(struct Book book)
{
	printf("书名:%s\n", book.title);
	printf("作者:%s\n", book.author);
	printf("价格:%f\n", book.price);
	printf("出版日期:%d-%d-%d\n", book.date.year,book.date.month,book.date.day);
	printf("出版社:%s\n", book.publisher);
}
int main()
{
	struct Book b1= {"xx","xx",0.0,0-0-0,"xx"},C;
	printf("请输入第一本书的信息\n");
	C=getinput(b1);
	printBook(b1);
	return 0;
}

 

  • 写回答

4条回答 默认 最新

  • CSDN专家-Time 2021-06-06 20:14
    关注

    scanf_s是要带长度的。

     

    而且非数组类型,scanf_s是要带取地址的。

    struct Book
    {
    	char title[128];
    	char author[40];
    	float price;
    	struct Date date;
    	char publisher;
    };
    struct Book getinput(struct Book book)
    {
    	printf("书名:");
    	scanf_s("%s", book.title,20);
    	printf("作者:");
    	scanf_s("%s", book.author,20);
    	printf("价格:");
    	scanf_s("%f", &book.price);
    	printf("出版日期:");
    	scanf_s("%d-%d-%d", &book.date.year, &book.date.month, &book.date.day);
    	printf("出版社:");
    	scanf_s("%s", &book.publisher,20);
    	return book;
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考