shengxizi 发表于 2020-1-19 18:13:57

vs2019字符串问题

本帖最后由 shengxizi 于 2020-1-19 18:13 编辑

vs2019在输入字符串时总有错误,请教各位大神,求求你们。

严重性        代码        说明        项目        文件        行        禁止显示状态
警告        C6064        缺少“scanf_s”的整型参数(对应于转换说明符“2”)。

严重性        代码        说明        项目        文件        行        禁止显示状态
警告        C4473        “scanf_s”: 没有为格式字符串传递足够的参数

代码如下:


#include<stdio.h>


struct Book
{
        char title;
        char author;
        float price;
        unsigned int date;
        char publisher;
};

int main()
{
        struct Book book;

        printf("请输入书名:\n");
        scanf_s("%s", book.title);
        printf("请输入作者:\n");
        scanf_s("%s", book.author);
        printf("请输入售价:\n");
        scanf_s("%f", &book.price);
        printf("请输入出版日期\n");
        scanf_s("%u", &book.date);
        printf("请输入出版社:\n");
        scanf_s("%s", book.publisher);

        printf("\n===========数据录入完毕=============\n\n");

        printf("书名:%s\n", book.title);
        printf("作者:%s\n", book.author);
        printf("售价:%.2f\n", book.price);
        printf("出版日期:%u\n", book.date);
        printf("出版社:%s", book.publisher);


        return 0;
}

4goodworld 发表于 2020-1-20 12:16:32

警告又不要紧

Croper 发表于 2020-1-20 13:01:13

scanf_s要在字符串后加上字符串的最大长度      scanf_s("%s", book.title,sizeof(book.title));
页: [1]
查看完整版本: vs2019字符串问题