Kirk Garvey wrote:
I for one would certainly be interested in seeing the code, it could serve as an example when to choose one I/O method over another.
Ok first the scanf method struct record{ char city[4]; char date[5]; char time[4]; float AirTemp; float WindSpeed; float WindDirection; float RainFall; }; int main() { char c; FILE *out; FILE *in; out = fopen("prog1.new", "wb"); in = fopen("prog1.dat", "rt"); record r; /*structure to store data to be written to binary file*/ while(fscanf(in, "\"%4s\",\"%5s\",%4s,%f,%f,%f,%f,\n", &r.city, &r.date, &r.time, &r.AirTemp, &r.WindSpeed, &r.WindDirection, &r.RainFall)!= EOF){ fwrite(&r, sizeof(record), 1, out); } return 0; } Then the C++ which I am sure could be much better since I knew very little about when I wrote this. int main() { FILE *out; /*binary file to be created*/ out = fopen("prog1.bin", "wb"); string line; /*memory to store data from text file one line at a time*/ record WeatherData; /*structure to store data to be written to binary file*/ ifstream in("prog1.dat"); /*input stream to read text file*/ while(in){ in >> line; strncpy(WeatherData.city, (line.substr(1,4)).c_str(), 4); strncpy(WeatherData.date, (line.substr(8,5)).c_str(), 5); strncpy(WeatherData.time, (line.substr(15,4)).c_str(), 4); line = line.substr(20); int begin = 0; int end = line.find(','); WeatherData.AirTemp = atof((line.substr(begin, end - begin)).c_str()); begin = ++end; end = line.find(',', end); WeatherData.WindSpeed = atof((line.substr(begin, end - begin)).c_str()); begin = ++end; end = line.find(',', end); WeatherData.WindDirection = atof((line.substr(begin, end - begin)).c_str()); begin = ++end; end = line.find(',', end); WeatherData.RainFall = atof((line.substr(begin, end - begin)).c_str()); fwrite(&WeatherData, sizeof(record), 1, out); } return 0; } Finally some sample data. . . "WASH","01/17",1745,0.0,0.0,0.0,0.00, "CAMA","01/17",1030,25.9,1.8,254.0,0.00, "CAMA","01/17",0945,26.2,0.4,323.0,0.00, "CAMA","01/17",1100,26.2,0.9,107.0,0.00, "SEIL","01/17",1030,26.2,2.2,152.0,0.00, "SEIL","01/17",1045,26.2,3.1,206.0,0.00, "CAMA","01/17",0930,26.4,0.2,331.0,0.00, "CAMA","01/17",0900,26.4,1.1,226.0,0.00, "CAMA","01/17",1015,26.4,1.3,305.0,0.00, "BUFF","01/17",0800,26.4,3.1,30.0,0.00, "CAMA","01/17",1000,26.6,1.1,6.0,0.00, -- Chris W Not getting the gifts you want? The Wish Zone can help. http://thewishzone.com