I need to use both malloc
and realloc
and am confused how to do it.
Assuming that the input file looks something like this:
a *b c
a
*a b *c
and I have structs set up as so:
typedef struct Unit {
bool hasAstericks;
char letter;
} unit;
typedef struct Line {
struct unit clause[4]
} line;
Is it possible to create a struct of type unit
from each letter add them to an array in struct Line
based off of the line they are on? I've tried using loops but couldn't create structs on the fly with them.
This is what I have tried:
int c;
filename = argv[1];
char *filename;
FILE *fp = fopen(filename, "r");
filename = (char *)malloc(size);
do {
c = fgetc(fp);
inputFile = (char *)realloc(inputFile, size + 1);
inputFile[n] = c;
n++;
size++;
} while (c != EOF);