warning: passing argument 1 of ‘gets’ from incompatible pointer type

gets() function takes one argument and this is a FILE-type. That's happening in my code but It doesn't work. I'm trying to get every single symbol from the file with a cycle like it happened in docs. What's the problem? The error happens in the 'load' function. String: "while ((symbol = gets(file)) != EOF)"

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

typedef struct
{
    char name[20];
    int age;
} person;

void save(char way[100], person *object);
void load(char way[100]);

FILE *file;

int main(void)
{
    char way[100] = "D:\\Projects\\C\\C06_WorkingWithFiles\\C004_ReadingAndWritingStructures.dat";

    person object = {"Tom", 15};
    person *p_object = &object;
    save(way, p_object);
    load(way);
    fclose(file);
    return 0;
}

void save(char way[100], person *object)
{
    if (fopen(way, "r") == NULL)
    {
        file = fopen(way, "w");
    }

    char *c = (char *)object;

    for (int i = 0; i < sizeof(person); i++)
    {
        putc(*c, file);
        c++;
    }
}

void load(char way[100])
{
    if ((file = fopen(way, "r")) == NULL)
    {
        perror("\nError");
        exit(0);
    }

    person object, *p_object = &object;
    char symbol, *c = (char *)p_object;

    while ((symbol = gets(file)) != EOF)
    {
        *c = symbol;
        c++;
    }

    printf("\nName: %s | Age: %d\n", p_object -> name, p_object -> age);
}


Read more here: https://stackoverflow.com/questions/64955724/warning-passing-argument-1-of-gets-from-incompatible-pointer-type

Content Attribution

This content was originally published by sosisochka at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: