0
你好,
下面的程序只能讀取輸入的數字,當魯爾房屋被侵犯別停下來,但1大問題是,它不會停止閱讀數字,更糟的是,不要在屏幕上打印它應該如何。
代碼:
#include <stdio.h>
#include <string.h>
void SIFT(int x_arr[ ], int y_arr[]);
int main()
{
int x[20] = {0} , y[20] = {0};
int m=0,temp=0,curr=0,i=0,j=0;
printf("Please enter your numbers now:\n\n");
/*enter numbers one by one. if x[i+1] value < x[i] value, err msg.
when user want to end the series he must enter '0' which means end of string (it wont included in x[]) */
while ((scanf("%d",&temp)) != '0')
{
if (temp >= curr)
{
x[i] = temp;
curr = temp;
i++;
}
else
{
printf("The numbers are not at the right order !\n\nProgram will now terminate...\n\n");
}
}
SIFT(x,y);
for (i=0 ; y[i]=='0' ; i++) /*strlen(y) without ('0')'s includes*/
m++;
/*Prints m , y's organs*/
printf("\n\nm = %d",m);
printf("Y = ");
while (y[j]!='0')
{
printf ("%d ,",y[j]);
j++;
}
return 0;
}
void SIFT(int x_arr[ ], int y_arr[])
{
int i=0,j=0;
while (x_arr[i] != '0')
{
if (x_arr[i] == x_arr[i+1]) /*if current val. equals next val. -> jump dbl at x_arr*/
{
y_arr[j] = x_arr[i];
i+=2;
j++;
}
else
{
y_arr[j]=x_arr[i];
i++;
j++;
}
}
}
請幫我解決這個問題... 日Thnx。
這不是以前的問題,儘管它幾乎是相同的代碼。 – Mat 2011-04-14 15:17:50
'scanf(「%d」,&temp)'「有2個結果」。一個這樣的「結果」是函數的返回值:1如果一切正常;否則爲0或EOF。另一個「結果」(當返回1時)是變量temp的值(用戶輸入的值)。你需要檢查「結果」...(如非常僞代碼)if(scanf()== 1){if(temp == 0)...; }' – pmg 2011-04-14 15:38:47