Hello World!
I am trying to read the contents of a file, that stores information on incoming messages. Each message consists of two lines: the first containing information about the reception time, and the sender, and the second line containing the message itself. I am trying to store the contents of the file in an array of structures. My structure definiton looks as follows:
My attempt at getting the information from the file into the array looks like this:Code:int i,j; struct msg{ int h; int m; int phone; char content[101]; }; char current_line[100]; FILE *src_file;
Here is how my text file looks...Code:i=1; j=0; while(fgets(current_line,100,src_file)){ if(i%2==1){ /*because every unpaired row contains information about when did the message arrive and from where, I only want to work with those rows...*/ sscanf(current_line,"%d%d%d",data[j].h,data[j].m,data[j].phone); j++; } }
The first number is the hour, the second is the minute and the third is the telephone number. Every second line contains the message. The program compiles, but when run, it gives a segmentation fault. I found some related threads, but couldn't get the right conclusion on what should be the problem here... any help, would be appreciated! Thanks!Code:9 11 123456789 Szia, mikor jossz? 9 13 434324223 Nem kerek ebedet! 9 14 434324223 Hova menjek erted? 9 16 343567452 Nem erek oda idoben. Hivd fel a fonokot es ments ki!



LinkBack URL
About LinkBacks


