2013-12-17 52 views
1

因此,我運行我的程序,並在此代碼集上輸入結構數據時,當我輸入1作爲希望輸入的數據時,我總是會遇到錯誤。雖然如果我再次輸入相同的數字,它似乎工作。我已經將它隔離爲代碼的這一部分,因爲當我評論這一切時它一切正常!驗證錯誤始終在第一次嘗試

任何人都可以提供幫助嗎?

do{ 
    puts("What is the packet type?"); 
    if(scanf(" %d", &records[*rCount].type) == 1 
     && records[*rCount].type >= 0 
     && records[*rCount].type <= 10) 
    { 
     valid = 1; 
    } 
    else 
    { 
     valid = 0; 
     getchar(); 
     puts("\nNot a valid input"); 
    } 
}while(valid!=1); 

結構的定義:

struct packet{ // declare structure for packet creation 
    int source; 
    int destination; 
    int type; 
    int port; 
    char data[51]; 
}; 
+0

你的結局如何? – rullof

+0

更新結構 – user3103598

+0

顯示'記錄[]' – chux

回答

1

問題似乎是一個struct packet records分配錯誤。

相關問題