RBerndt
2010-12-09 11:38:53 UTC
A buddy of mine suggested using the Feof function, but I have no idea how it works. My code is below, currently it just reads the same line over and over.
If someone could give me some pointers on how to properly use a while loop feof combination id be extremely grateful
The data file contains 50+ lines of unsorted data...(top 5 lines as an example)
500001012803102008108305200010
100000010103312008110004000020
610000012301112007304303000025
500002020404232007218155200010
Im supposed to convert the data into this format:
5000010128,03/10/2008,1,08:30,f5.2,000
---------------------------------Here is my Code------------------------------------…
#include
#include
#include
#define FILENAME "machine_samples_1.txt"
int main ()
{
/* Declare and Initialize variables */
int data_pts=0, Identifier, Day, Month, Year, Shift, Hour, Minute, Format_Width, Format_Fractional_Part, Format_Fract_Part, Number_Data_Pts;
FILE* machine_samples;
/* Open file and read first data points*/
machine_samples = fopen(FILENAME,"r");
fscanf(machine_samples,"%10d %02d %2d %4d %1d %02d %02d %1d %1d %05d",&Identifier,&Day,&Month,&Year,&Shi…
while (!feof(machine_samples))
{
printf("%10d," "%02d/" "%2d/" "%4d," "%1d," "%02d:" "%02d," "f%1d" ".%1d," "%05d" ,Identifier,Day,Month,Year,Shift, Hour, Minute, Format_Width, Format_Fract_Part, Format_Fract_Part, Number_Data_Pts);
}
return EXIT_SUCCESS;
}