![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binary txt file received when i use uuencode to send txt file as attachment | ash22 | UNIX for Dummies Questions & Answers | 2 | 04-24-2008 05:03 PM |
| compiled binary file gives "cannot execute binary file" | scgupta | SUN Solaris | 0 | 07-12-2006 10:59 PM |
| binary file | markms | UNIX for Dummies Questions & Answers | 1 | 04-07-2006 06:40 AM |
| binary file | ramneek | UNIX for Dummies Questions & Answers | 1 | 09-13-2005 02:02 PM |
| Reading a binary file in text or ASCII format | Nagendra | High Level Programming | 2 | 09-07-2005 08:08 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist?
this is my fread line Code:
fread(&file_data,sizeof(struct book_type),1,fileSave); thanks! primal here is some other information that might be required... global variable Code:
struct book_type{
char title[30];
float price;
char authorName[30];
struct book_type * link;
};
Code:
fwrite(book_head,sizeof(struct book_type),1,fileSave); fwrite(temp,sizeof(struct book_type),1,fileSave); Code:
void display_File_Data(){
char ch;
int count=1;
struct book_type * file_data;
rewind(fileSave);
printf("\nSerial Number\tTitle\t\tAuthor\t\tPrice\n");
do{
fread(&file_data,sizeof(struct book_type),1,fileSave);
if(feof(fileSave)){
break;
}
else{
printf("%d\t\t%s\t%s\t$%2.2f\n",count,file_data->title,file_data->authorName,file_data->price);
count++;
}
}while(!feof(fileSave));
printf("\nPress enter to continue...");
ch=getchar();
getchar();
}
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
someone else might have a better answer than me; but when i used to C program (many years ago!) and had memory errors it was often because I tried to read (and write) into memory an amount larger than was allocated and ... a coredump!
Quote:
that would be my first guess.... the storage area (in memory) for file_data must be large enough to store the fread size from stream or you will get a memory error core dump..... how big is your memory area? did you initialize it or malloc some nice space? |
|
#3
|
|||
|
|||
|
Hi
It seems like the core dump is generated at the 2nd printf statement inside your display_File_Data(). You have declared file_data as a pointer to the structure....but didnt allocate memory using malloc/calloc. Do the necessary dynamic allocation and it should work this time. Cheers Deepa |
|
#4
|
|||
|
|||
|
Hi
Just one more addition...... If you have gdb/dbx debugging tool in ur machine, u can get the exact statement where the core was dumped. Cheers Deepa |
|||
| Google The UNIX and Linux Forums |