Good day here everybody. I am kind of new in programming. I have to copy stuff(textfile) to array through struct. I already allocated the memory for it. I have no clue how to copy stuff to that dynamic array. After every log (7lines) there is one white line. In this function i have to just alocate it and copy it to array and print it. I will be doing other stuff like, finding item, adding new logs etc. in different functions. Can somebody help me please?
inf.txt this is my file
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char name[50];
char gen;
int birth;
char car;
int type;
int fee;
long date;
}log;
int copy() {
FILE *file;
char logchar;
int line=1,numlog=0,i;
log *p;
file = fopen("inf.txt", "r");
while(!feof(file))
{
logchar = fgetc(file);
if(logchar== '\n')
{
line++;
}
}
if(line%8==0)
{
numlog=(line/8);
}
p=(log*)malloc(numlog*sizeof(log));