| | |
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 arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. lowest match matrix microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi





