Are there alternate implementations of GNU getline interface?

后端 未结 5 1227
醉酒成梦
醉酒成梦 2020-11-28 09:48

The experiment I am currently working uses a software base with a complicated source history and no well defined license. It would be a considerable amount of work to ration

5条回答
  •  无人及你
    2020-11-28 10:03

    Try using fgets() instead of getline(). I was using getline() in Linux and it was working well until I migrated to Windows. The Visual studio did not recognize getline(). So, I replace the character pointer with character, and EOF with NULL. See below:

    Before:

    char *line = (char*) malloc(sizeof(char) * 1000);
    size_t size = 1000 * sizeof(char);
    FILE *fp = fopen(file, "r");
    while(getline(&line, &size, fp) != EOF) {
       ...
    }
    free(line);
    

    After:

    char line[1000];
    size_t size = 1000 * sizeof(char);
    while(fgets(&line, &size, fp) != NULL) {
       ...
    }
    

提交回复
热议问题