用VS2019编C++结构体做参数,在函数里引发读写冲突怎么解决???
用VS2019编C++结构体做参数,在函数里引发读写冲突怎么解决??? 发 代 码 永恒的蓝色梦想 发表于 2020-5-19 19:31发 代 码
#include <stdio.h>
struct Book
{
char title;
char author;
float price;
unsigned int date;
char publisher;
};
int main(void)
{
struct Book book;
printf("请输入书名:");
scanf("%s", book.title);
printf("请输入作者:");
scanf("%s", book.author);
printf("请输入售价:");
scanf("%f", book.price);
printf("请输入出版日期:");
scanf("%d", book.date);
printf("请输入出版社:");
scanf("%s", book.publisher);
printf("数据录入完毕");
printf("书名:%s\n",book.title);
printf("作者:%s\n", book.author);
printf("售价:%f\n", book.price);
printf("日期:%d\n", book.date);
printf("出版社:%s\n", book.publisher);
} 永恒的蓝色梦想 发表于 2020-5-19 19:31
发 代 码
到输入价格的时候就会出错,出入日期也会出错 lyt547659789 发表于 2020-8-1 10:28
到输入价格的时候就会出错,出入日期也会出错
你忘了取地址:#include <stdio.h>
struct Book
{
char title;
char author;
float price;
unsigned int date;
char publisher;
};
int main(void)
{
struct Book book;
printf("请输入书名:");
scanf("%s", book.title);
printf("请输入作者:");
scanf("%s", book.author);
printf("请输入售价:");
scanf("%f", &book.price);
printf("请输入出版日期:");
scanf("%d", &book.date);
printf("请输入出版社:");
scanf("%s", book.publisher);
printf("数据录入完毕");
printf("书名:%s\n",book.title);
printf("作者:%s\n", book.author);
printf("售价:%f\n", book.price);
printf("日期:%d\n", book.date);
printf("出版社:%s\n", book.publisher);
} 永恒的蓝色梦想 发表于 2020-8-1 10:35
你忘了取地址:
谢谢 lyt547659789 发表于 2020-8-1 12:31
谢谢
卧槽你不是楼主? {:10_257:}{:10_257:}{:10_257:}
页:
[1]