Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取glibc检测到linux而非windows的双重释放或损坏 我对C++非常陌生,所以这个代码基本上是用G++编译的。当我在Windows上编译它时,它可以工作,但它在Linux上进行核心转储。有人能看出我做错了什么吗_C++_C - Fatal编程技术网

获取glibc检测到linux而非windows的双重释放或损坏 我对C++非常陌生,所以这个代码基本上是用G++编译的。当我在Windows上编译它时,它可以工作,但它在Linux上进行核心转储。有人能看出我做错了什么吗

获取glibc检测到linux而非windows的双重释放或损坏 我对C++非常陌生,所以这个代码基本上是用G++编译的。当我在Windows上编译它时,它可以工作,但它在Linux上进行核心转储。有人能看出我做错了什么吗,c++,c,C++,C,下面是更多的代码: #include <stdio.h> #include <string.h> #include <stdlib.h> #include "student.h" #define MAX_LINE_LENGTH 200 #define DELIMITER ',' struct _node { StudentRecord student; struct _node *next; }; typedef struct _node

下面是更多的代码:

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

#define MAX_LINE_LENGTH 200
#define DELIMITER ','

struct _node
{
    StudentRecord student;
    struct _node  *next;
};
typedef struct _node Node;

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        fprintf(stderr, "Usage: demo studentdata_2.txt\n");
        return 1;
    }

    FILE* fp = fopen("studentdata_2.txt", "r");
    if (!fp)
    {
        fprintf(stderr, "Cannot read file\n");
        return 2;
    }

    char  line[MAX_LINE_LENGTH + 1];

    Node *head = 0; 
    Node *latest;

    fgets(line, MAX_LINE_LENGTH, fp);
    printf("reaches here\n");
    while (!feof(fp))
    {
        if (strlen(line) >= 3)
        {

            Node *current = (Node*)malloc(sizeof(Node));
            current->next = 0;
            if (!head) 
                head = current;
            else
                latest->next = current;
            latest = current;

            parseStudent(line, DELIMITER, &current->student);
        }

        fgets(line, MAX_LINE_LENGTH, fp);
    }
    fclose(fp);
    printf("doesn't reach here\n");

    int count = 0;
    float sum = 0;
    Node* ptr = head;
    while (ptr)
    {
        count++;
        sum += ptr->student.m_score;
        ptr = ptr->next;
    }
    float average = sum / count;

    ptr = head;


    ptr = head;
    while (ptr)
    {
        releaseStudent(&ptr->student);

        Node* nxt = ptr->next;

        free(ptr);

        ptr = nxt;
    }

    return 0;
}

为什么把这个标记为C和C++?他们是不同的语言。如果你只使用C结构,为什么要用g++编译它?你能提供一个完整的源文件,包括includes吗?我在你的代码中没有看到免费的。为什么要释放malloc分配的内存?应该在调试器中运行程序,或者使用诸如查找内存问题的工具。可能对你有用-你的if strlenline>=3是一种破解方法,可以避免它是错误的。然而,这与你的实际问题无关。