#include<stdio.h>
#include<stdlib.h>
#define BUFFERSIZE 1024/*允許處理的最長行有1024個字元*/
/*編譯環境vs2013*/
void main()
{
int a, b, sum; /*将輸入的兩個數分别存儲在變量a和b中,sum=a+b*/
char buffer[BUFFERSIZE];
printf("***********************************\n");
printf("* Welcome to use our counter *\n");
printf("* Input two integers in one line *\n");
printf("* The sum will be printed *\n");
printf("* Input the char '#' to quit *\n");
printf("***********************************\n");
/*從标準輸入(stdin)讀取輸入的資料,存儲在buffer中.
如果讀取的第一個字元是'#'則推出程式*/
while ((fgets(buffer, BUFFERSIZE, stdin) != NULL) && (buffer[0] != '#'))
{
if (sscanf_s(buffer, "%d %d", &a, &b) != 2) /*處理存儲在buffer中的一行資料*/
{
printf("The input is skipped:%s", buffer);/*如果輸入的數字不是兩個則報錯*/
continue; /*繼續讀取下一組資料*/
}
sum = a + b; /*計算a與b的和*/
printf("The sum of %d and %d is %d\n", a, b, sum); /*輸出計算結果*/
}
return;
}
網名:浩秦;
郵箱:root#landv.pw;
隻要我能控制一個國家的貨幣發行,我不在乎誰制定法律。金錢一旦作響,壞話隨之戛然而止。