鱼C论坛

 找回密码
 立即注册
查看: 1567|回复: 6

[已解决]哪位大佬帮忙看看怎么解决(小白一脸懵逼)

[复制链接]
发表于 2022-7-4 20:46:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
警告信息:
警告        C6064        缺少“scanf_s”的整型参数(对应于转换说明符“2”)。       
警告        C4473        “scanf_s”: 没有为格式字符串传递足够的参数        Project1       

#include<stdio.h>
int main(void)
{
        long ilong;
        short ishort;
        int num1 = 1;
        int num2 = 2;
        char ichar[10] ;
        printf("Enter the long interger:\n");
        scanf_s("%ld", &ilong);
        printf("Enter the short interger:\n");
        scanf_s("%hd", &ishort);
        printf("Enter the number:\n");
        scanf_s("%d*%d", &num1, &num2);
        printf("Enter the string but only show three character\n");
        scanf_s("%3s", ichar);

        printf("the long interger is %ld\n", ilong);
        printf("the short interger is %hd\n", ishort);
        printf("the num1 is :%d\n", num1);
        printf("the num2 is :%d\n", num2);
        printf("the three character are :%s\n", ichar);

        return 0;
}
最佳答案
2022-7-4 21:27:11
#include<stdio.h>
int main(void)
{
    long ilong;
    short ishort;
    int num1 = 1;
    int num2 = 2;
    char ichar[10];
    printf("Enter the long interger:\n");
    scanf_s("%ld", &ilong);
    printf("Enter the short interger:\n");
    scanf_s("%hd", &ishort);
    printf("Enter the number:\n");
    scanf_s("%d*%d", &num1, &num2);
    printf("Enter the string but only show three character\n");
    scanf_s("%3s", ichar, 10); // <---------------------------------- 注意这里

    printf("the long interger is %ld\n", ilong);
    printf("the short interger is %hd\n", ishort);
    printf("the num1 is :%d\n", num1);
    printf("the num2 is :%d\n", num2);
    printf("the three character are :%s\n", ichar);

    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-7-4 21:21:15 From FishC Mobile | 显示全部楼层
scanf_s并不通用,除了微软的visual stdio 系列
其他的编译器好像都不认
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-7-4 21:23:57 | 显示全部楼层
wp231957 发表于 2022-7-4 21:21
scanf_s并不通用,除了微软的visual stdio 系列
其他的编译器好像都不认

我用的就是vs2022,听说scanf函数改了,之前的编程书上的代码运行起来总会出错
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-4 21:27:11 | 显示全部楼层    本楼为最佳答案   
#include<stdio.h>
int main(void)
{
    long ilong;
    short ishort;
    int num1 = 1;
    int num2 = 2;
    char ichar[10];
    printf("Enter the long interger:\n");
    scanf_s("%ld", &ilong);
    printf("Enter the short interger:\n");
    scanf_s("%hd", &ishort);
    printf("Enter the number:\n");
    scanf_s("%d*%d", &num1, &num2);
    printf("Enter the string but only show three character\n");
    scanf_s("%3s", ichar, 10); // <---------------------------------- 注意这里

    printf("the long interger is %ld\n", ilong);
    printf("the short interger is %hd\n", ishort);
    printf("the num1 is :%d\n", num1);
    printf("the num2 is :%d\n", num2);
    printf("the three character are :%s\n", ichar);

    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-4 21:28:03 From FishC Mobile | 显示全部楼层
NAGAYA 发表于 2022-7-4 21:23
我用的就是vs2022,听说scanf函数改了,之前的编程书上的代码运行起来总会出错

还有一个参数,是写入数据的长度
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-4 21:29:16 | 显示全部楼层
可以用 gets() 和 puts() 函数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-7-4 21:34:22 | 显示全部楼层

谢谢大佬,还有就是第十四行那里这样写的话时只能输入一个数吗?我想输入两个的时候程序好像就终止了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 06:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表