c - 第一次尝试总是出现验证错误

标签 c validation

因此,我运行我的程序,在为这组代码的结构输入数据时,当我输入 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/

相关文章:

将结构值复制到缓冲区(客户端)并将其检索到缓冲区(服务器端)

c - 需要返回一个整数,其二进制表示形式与 i 的反向表示相同。

c# - 用 C# dll 替换 c api dll 而不影响客户端

validation - iOS7 中非消耗性产品的服务器端收据验证和 transactionReceipt 弃用

php - 使用 PHP 将类添加到输入

java - 验证信用卡详细信息

python - 妖艳 : give error line in yaml file

java - 在 Java 中如何重置 While 循环而不破坏它?

c - 获取 bash 命令的输出并将其作为命令行参数传递给 c 可执行文件(管道)

c - 与指针、数组和标准输入明显混淆