| | |
file input and output
![]() |
•
•
Join Date: Sep 2003
Posts: 1
Reputation:
Solved Threads:
0
Hello
C problem
I am having problems saving a structure to a text file. My structure is below.
What is the best way to save this to a file and open it from a file and display it on the screen. I have tried several ways but can't get it to work propertly.
I have tried using fread and fwrite, but having problems with it.
This is what l have done so far. It is bits of code that does not work
C problem
I am having problems saving a structure to a text file. My structure is below.
What is the best way to save this to a file and open it from a file and display it on the screen. I have tried several ways but can't get it to work propertly.
I have tried using fread and fwrite, but having problems with it.
This is what l have done so far. It is bits of code that does not work
C Syntax (Toggle Plain Text)
//Structure that Holds details for all the customers struct freight{ char name[20]; char address[40]; char goods[30]; int quantity; char destination[30]; } customerDetails[20]; //Code for opening the file if((fileCustomers = fopen(fileName, "wb")) == NULL) printf("\nCannot save this record"); //Code for writing to the file for(i=0; i<=recordNumber; i++){ if(fwrite(&customerDetails[i], sizeof(struct freight),1,fileCustomers) != 1){ printf("\nError saving customer records"); exit(1); } } fclose(fileCustomers); //code for opeing the file if((fileCustomers = fopen(fileName, "rb")) == NULL){ printf("\nCannot not find customer records on disk"); printf("\nOr file may not have been created yet"); } //Code for reading from the file. for(i=0; i<=2; i++){ if(fread(&customerDetails[i],sizeof(struct freight),1,fileCustomers) != 1){ printf("\nError opening customer records"); exit(1); } } fclose(fileCustomers);
![]() |
Similar Threads
- File input output please help :( (C)
- Server file input? (Java)
- Writing a file input and output program. (C++)
- Getting all data from an input and output file (C++)
Other Threads in the C Forum
- Previous Thread: capturing text
- Next Thread: string to integer array transformation
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory feet fflush fgets file floatingpointvalidation fork forloop frequency givemetehcodez grade gtkgcurlcompiling gtkwinlinux hacking highest histogram inches input intmain() iso kernel keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match microsoft mqqueue mysql number oddnumber odf opendocumentformat openwebfoundation owf pattern pdf performance posix probleminc process program programming radix recv recvblocked repetition research reversing scanf scheduling segmentationfault sequential single socket socketprograming socketprogramming stack standard string systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi





