pragma mark scanf函數(shù) 實現(xiàn)原理
/*
快捷鍵
添加斷點: command +\
利用scanf從輸入緩存區(qū)中獲取用戶輸入的數(shù)據(jù)
只要類型不匹配,那么scanf函數(shù)的函數(shù)就會自動結(jié)束,并且不會修改對應(yīng)的變量的值亮元。也不會取走輸入緩存區(qū)中保存
*/
pragma mark 代碼
#include <stdio.h>
int main()
{
// 1. 提醒用戶
// printf("請輸入兩個整數(shù),整數(shù)之間用逗號隔開,使用回車結(jié)束\n");
// 2.定義變量保存用戶輸入的數(shù)據(jù)
int num1, num2;
char charValue;
// 3.接收用戶輸入的數(shù)據(jù)
// num1 = 123, charValue = + ,num2 = 456;
scanf("%i%c%i",&num1,&charValue,&num2);
// 4.求差
// int result = num1 - num2;
// 5.輸出驗證
// printf("result = %i\n",result);
printf("num1 = %i, charVlaue = %c, num2 = %i",num1,charValue,num2);
// 用戶輸入 --> 輸入緩存區(qū) --> scanf
char charValue2;
int num3;
scanf("%c%i",&charValue2 ,&num3);
printf("charValue2 = %c,num3 = %i",charValue2,num3);
//
return 0;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者