001_vs里面的scanf问题

 

1、把scanf改为scanf_s;

2、在新建项目时取消勾选“SDL检查”;

3、在项目属性里关闭SDL;

4、在项目属性----C/C++ ----命令行中添加:/D _CRT_SECURE_NO_WARNINGS

5、在程序最前面加:#define_CRT_SECURE_NO_DEPRECATE

scanf_count小于等于usart_count,则scanf_count_old==usart_count。 以下是比较函数的代码: ```c int compare(int scanf_count, int usart_count, int scanf_count_old) { if (usart_count == 0) { if (scanf_count > scanf_count_old) { scanf_count_old = scanf_count; } } else { if (scanf_count > usart_count) { printf("设备没有取完\n"); } else { scanf_count_old = usart_count; } } return scanf_count_old; } ``` 使用方法: 1. 将以上代码放入你的程序中。 2. 调用`compare()`函数,传入三个变量(`scanf_count`、`usart_count`、`scanf_count_old`),并接收返回值。 ```c scanf_count_old = compare(scanf_count, usart_count, scanf_count_old); ``` 注意,`scanf_count_old`需要在调用函数之前定义并初始化。 完整示例: ```c #include <stdio.h> int compare(int scanf_count, int usart_count, int scanf_count_old); int main() { int scanf_count = 5; int usart_count = 0; int scanf_count_old = 0; scanf_count_old = compare(scanf_count, usart_count, scanf_count_old); printf("scanf_count_old = %d\n", scanf_count_old); usart_count = 6; scanf_count_old = compare(scanf_count, usart_count, scanf_count_old); printf("scanf_count_old = %d\n", scanf_count_old); scanf_count = 7; scanf_count_old = compare(scanf_count, usart_count, scanf_count_old); printf("scanf_count_old = %d\n", scanf_count_old); return 0; } int compare(int scanf_count, int usart_count, int scanf_count_old) { if (usart_count == 0) { if (scanf_count > scanf_count_old) { scanf_count_old = scanf_count; } } else { if (scanf_count > usart_count) { printf("设备没有取完\n"); } else { scanf_count_old = usart_count; } } return scanf_count_old; } ``` 输出结果: ``` scanf_count_old = 5 scanf_count_old = 6 scanf_count_old = 7 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值