A - 編寫一個程序,從用戶獲取數字,直到用戶輸入「-1」。然後程序應該將數字寫入文件。
我已經這樣做了,但我不能做B中的一個:
乙 - 更新您的程序和打印直方圖到該文件如下所示。將您的代碼保存在一個新文件中。
例
report.dat:
5 *****
8 ********
11 ***********
3 ***
代碼在:
#include <stdio.h>
int main() {
int num;
const int senitel = -1;
FILE*fileId;
printf("Please enter integer number (-1 to finish)");
scanf("%d", &num);
fileId = fopen("report.dat", "w");
while (num != senitel) {
fprintf(fileId, "%d \n", num);
scanf("%d", &num);
}
fclose(fileId);
return 0;
}
我認爲你唯一缺少的星星在每行的末尾,不好嗎?應該不會那麼難以將輸入數字轉換爲整數並在循環中創建您需要的恆星數量 – 2014-11-20 21:46:32
這些行:scanf(「%d」,&num);應寫爲:if(1!= scanf(「注意格式化字符串中的前導'',以使scanf跳過/消耗空白(如換行符) – user3629249 2014-11-20 23:29:35