哪位大佬帮忙看看怎么解决(小白一脸懵逼)
警告信息:警告 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 ;
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;
} scanf_s并不通用,除了微软的visual stdio 系列
其他的编译器好像都不认 wp231957 发表于 2022-7-4 21:21
scanf_s并不通用,除了微软的visual stdio 系列
其他的编译器好像都不认
我用的就是vs2022,听说scanf函数改了,之前的编程书上的代码运行起来总会出错 #include<stdio.h>
int main(void)
{
long ilong;
short ishort;
int num1 = 1;
int num2 = 2;
char ichar;
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;
} NAGAYA 发表于 2022-7-4 21:23
我用的就是vs2022,听说scanf函数改了,之前的编程书上的代码运行起来总会出错
还有一个参数,是写入数据的长度 可以用 gets() 和 puts() 函数 傻眼貓咪 发表于 2022-7-4 21:27
谢谢大佬,还有就是第十四行那里这样写的话时只能输入一个数吗?我想输入两个的时候程序好像就终止了。
页:
[1]