Hello mates and sorry for my english! Firstly, could I ask help at this forum with my bugs in case I cant figure out the problem on my own?
So to begin with, i have a file that contains some logs that are structured like that:
2015-07-22 09:07:00 1346144 13.02 25.36 6.606 4.012 0.845 26.3
2015-07-22 09:08:00 1346145 13.02 25.38 6.656 4.057 0.848 26.4
2015-07-22 09:09:00 1346146 13.02 25.43 6.667 4.086 0.849 26.45
2015-07-22 09:10:00 1346147 13.02 25.46 6.663 4.109 0.851 26.44
2015-07-22 09:11:00 1346148 13.02 25.5 6.657 4.131 0.856 26.51
2015-07-22 09:12:00 1346149 13.02 25.53 6.693 4.17 0.862 26.53
2015-07-22 09:13:00 1346150 13.02 25.56 6.723 4.205 0.865 26.71
2015-07-22 09:14:00 1346151 13.02 25.6 6.734 4.233 0.866 26.64
So I managed to pass each line to a Log structure that which looks like:
typedef struct Log {
char field1[11] ;
char field2[9] ;
int field3 ;
float field4 ;
float field5 ;
float field6 ;
float field7 ;
float field8 ;
float field9 ;
}log_t, *plog;
I managed to pass a line but i get in trouble when I try to pass more lines. I try to make a pointer pointer to this structure as i know that arrays are pointers. This is my code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef struct Log {
char field1[11] ;
char field2[9] ;
int field3 ;
float field4 ;
float field5 ;
float field6 ;
float field7 ;
float field8 ;
float field9 ;
}log_t, *plog;
FILE* OpenFile(const char* path)
{
FILE* file = NULL;
file = fopen(path, "r");
if (file == NULL)
printf("File cant be opened\n");
else
printf("File is opened\n");
return file;
}
plog CreateLog(FILE* file)
{
plog log = (plog)malloc(sizeof(log));
fscanf(file, "%s", log->field1);
fscanf(file, "%s", log->field2);
fscanf(file, "%d", &(log->field3));
fscanf(file, "%f", &(log->field4));
fscanf(file, "%f", &(log->field5));
fscanf(file, "%f", &(log->field6));
fscanf(file, "%f", &(log->field7));
fscanf(file, "%f", &(log->field8));
fscanf(file, "%f", &(log->field9));
return log;
}
void PrintLog(log_t log)
{
printf("%s", log.field1);
printf("%s", log.field2);
printf("%d", log.field3);
printf("%f", log.field4);
printf("%f", log.field5);
printf("%f", log.field6);
printf("%f", log.field7);
printf("%f", log.field8);
printf("%f", log.field9);
}
int main()
{
FILE* file;
file = OpenFile("DataMeteoE4.txt");
//plog log = CreateLog(file);
plog* logs;
logs = (plog*)malloc(sizeof(log_t) * 10);
for (int i = 0; i < 10; i++)
{
logs[i] = CreateLog(file);
}
//PrintLog(*log);
fclose(file);
return 0;
}
It crashes with exception: " .exe has triggered a breakpoint" Can anyone help me pls