1
我試圖創建一個函數,將顯示20多個數據或退出循環。最大的問題是確認,因爲我希望用戶輸入Y或N.我該如何解決這個問題?輸出20更多數據
void DisplayData(int StartIndex, int EndIndex)
char confirm = 0;
while (confirm != 'n' || 'N')
{
int index = 1;
for (index = StartIndex; index < EndIndex; index++)
{
printf("%d. %d.%d.%d.%d => %d.%d.%d.%d | ", index, sourceIP[index][0], sourceIP[index][1], sourceIP[index][2], sourceIP[index][3],
destinationIP[index][0], destinationIP[index][1], destinationIP[index][2], destinationIP[index][3]);
if (protocol[index][3] == 0)
{
printf("%c%c%c", protocol[index][0], protocol[index][1], protocol[index][2]);
}
else if (protocol[index][4] == 0)
{
printf("%c%c%c%c", protocol[index][0], protocol[index][1], protocol[index][2], protocol[index][3]);
}
printf("| %d | %d\n", source_port[index], destination_port[index]);
}
printf("Display More: <Y>ES | <N>O: ");
scanf("%c", &confirm);
if (confirm == 'y' || confirm == 'Y')
{
StartIndex += 20;
}
else if (confirm == 'n' || 'N')
{
break;
}
else
{
printf("Invalid Input");
}
}
如果你在[CodeReview](http://codereview.stackexchange.com/)中發佈這個,可能會更好。 –