
uj5u.com熱心網友回復:
沒有輸出的原因是還沒有從while回圈中退出來,即while是當=='\n'時退出;修改一下
#include <stdio.h>
#define MAX_ARR_SIZE (50)
int main(void)
{
int array[MAX_ARR_SIZE], *p;
int i = 0;
while (i < MAX_ARR_SIZE && scanf("%d", &array[i++]) == 1)
;
p = array + i - 2;
for (; p >= array; p--)
printf("%d\n", *p);
return 0;
}
供參考~
#include <stdio.h>
#define MAX_ARR_SIZE (50)
int main(void)
{
int array[MAX_ARR_SIZE], *p;
int i = 0;
p = array;
while (p < array + MAX_ARR_SIZE && scanf("%d", p++) == 1)
;
//p = array + i - 2;
for (p = p - 2; p >= array; p--)
printf("%d\n", *p);
return 0;
}
供參考~
uj5u.com熱心網友回復:
終止輸入的方式Linux用ctrl+d,Windows用ctrl+z
uj5u.com熱心網友回復:
我寫的程式為什么退不出來,能解釋一下嗎?不是輸入換行就會退出嗎?
uj5u.com熱心網友回復:
scanf的回傳值不會等于'\n',看一下scanf的回傳值你就知道了:
return the number of input items successfully matched and assigned, which can be fewer than provided for, or even
zero in the event of an early matching failure.
return the number of input items successfully matched and assigned, which can be fewer than provided for, or even
zero in the event of an early matching failure.
這是scanf回傳值的描述,可以參考一下~
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/279394.html
標籤:C語言
上一篇:OpenGL繪制3D灰度圖
