因此,我运行我的程序,在为这组代码的结构输入数据时,当我输入 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];
};
最佳答案
问题似乎是 struct packet records
的分配错误。
关于c - 第一次尝试总是出现验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20625394/