c - `Build Error` 错误 -1073741819 - C

标签 c file-io struct linked-list

我的任务是从游戏 Boggle 中获取每个骰子的所有可能字母的数据文件。这是数据文件的副本:

   D R L X E I
   C P O H S A
   N H N L Z R
   W T O O T A
   I O S S E T 
   N W E G H E
   B O O J A B
   U I E N E S
   P S A F K F
   I U N H M Qu
   Y R D V E L
   V E H W H R
   I O T M U C
   T Y E L T R
   S T I T Y D
   A G A E E N

每个骰子取 6 个字母,这些字母存储在链表中。当我尝试运行以下代码时,我不断收到错误代码:C:\Dev-Cpp\Makefile.win [Build Error] [Untitled1.o] Error -1073741819

我试过使用 3 种不同的 IDE,但似乎总是遇到一些编译问题。我似乎无法弄清楚我要去哪里错了!无论如何这还没有完成,但我宁愿在我继续深入之前弄清楚这一点。提前致谢!

代码:

#include <string.h>
#include <stdlib.h>
#include <stdio.h>


#define LENGTH 80

struct boggleDataNode{
       char data[3];
       struct boggleDataNode *nextData;
}*head;

struct boggleDieSideNode{
       char dieSideData[3];
       struct boggleDieSideNode *nextSide;
}*head1;

void readData(struct boggleDataNode temp);

int main(){
    int counter = 0;
    struct boggleDataNode *head;
    struct boggleDieSideNode *head1;
    struct boggleDataNode *temp;
    *head = NULL;
    *head1 = NULL;
    *temp = *head;
    readData(*temp);


    system("pause");
    return 0;
}
void readData(struct boggleDataNode temp){
    //initializing variables including
    //opening the input file
    FILE *input = fopen("BoggleData.txt","r");
    int name =0; 
    int id=0;
    char data[96] ={};

    //error checking that the file opened
    if (input == NULL){
        fprintf(stderr, "Can't open input file!\n");
        exit(1);
    }
    while( fscanf(input, "%s", &data) != EOF)
           printf("%s", data);

}

最佳答案

在你的代码中,改变

struct boggleDataNode{
       char data[3];
       struct boggleDataNode *nextData;
}*head;

struct boggleDataNode{
       char data[3];
       struct boggleDataNode *nextData;
};

因为看起来您无论如何都不需要该结构的全局指针。根据您的使用情况,它将被本地 head 隐藏

head1 也是如此。

接下来,您将 NULL 分配给指针本身,而不是分配给它指向 的变量。 (FWIW,NULL 本身是一个指针,不过是一个无效指针)。

改变

*head = NULL;

head = NULL;

关于c - `Build Error` 错误 -1073741819 - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31013245/

相关文章:

c - 在C中为txt添加一个空格

Python IO 大师 : what are the differences between these two methods?

c - 为什么此 C 代码片段中的 NULL 取消引用不会导致未定义的行为

C中用union将串口数据转为float

c - C 中的语法 else if

c - C 中的 ~~x 和 !!x 有什么区别?

Java 和文件列表

c++ - 函数在 main 和 library 中调用不同的行为

python - Cython:在结构中嵌套 union

c - 宏扩展期间出现意外语法错误