Guest_imported
New member
- Jan 1, 1970
- 0
I have Text file as below on the left.
6.00 Peter 6.00 Peter
10.30 Joa 10.30 Joa
12.45 Mac 12.44 Mac
1.00 Jack 13.00 Jack
5.00 J9 17.00 J9
5.45 Liz ..
10.55 Mark ..
11.45 Peter 23.45 Peter
12.05 Mac 00.00 Mac
1.25 Joa 1.25 Joa
5.55 J9 5.55 J9
I am tring to read the above file from the start to end and convert the time to 24 hour time as shown on the right and save the text file with the converted time.
Heres what i have coded so far.
// Program to open .txt file covert and save to new name.
#include <stdio.h>
void main( void )
{
FILE *fp; // file pointer
float *time; // store original time
int nTimeFlag=0; // time flag
float nTmpTime=0.00; // ref time.
char buffer[900]; // store in read data
int i, ch;
/* Open file for reading (fail if data does not exist) */
if( (fp = fopen( "test.txt", "rt" )) == NULL )
printf( "error opening file \n" );
else
printf( "file opened \n" );
/* Read in characters and place them in "buffer": */
ch = fgetc( fp);
for( i=0; (i < 899 ) && ( feof(fp ) == 0 ); i++ )
{
// store original time in array time
buffer = (char)ch;
*time = buffer;
if (*time < nTmpTime)
{
if (!nTimeFlag)nTimeFlag=1;
else nTimeFlag =0;
}
buffer=*time;
if (nTimeFlag)*time +=12.00;
buffer =*time;
ch = fgetc( fp );
}
printf( "%s\n",buffer);
fclose(fp);
}
Can some one pls help me, or put me in the right direction.
Thanks!!.
6.00 Peter 6.00 Peter
10.30 Joa 10.30 Joa
12.45 Mac 12.44 Mac
1.00 Jack 13.00 Jack
5.00 J9 17.00 J9
5.45 Liz ..
10.55 Mark ..
11.45 Peter 23.45 Peter
12.05 Mac 00.00 Mac
1.25 Joa 1.25 Joa
5.55 J9 5.55 J9
I am tring to read the above file from the start to end and convert the time to 24 hour time as shown on the right and save the text file with the converted time.
Heres what i have coded so far.
// Program to open .txt file covert and save to new name.
#include <stdio.h>
void main( void )
{
FILE *fp; // file pointer
float *time; // store original time
int nTimeFlag=0; // time flag
float nTmpTime=0.00; // ref time.
char buffer[900]; // store in read data
int i, ch;
/* Open file for reading (fail if data does not exist) */
if( (fp = fopen( "test.txt", "rt" )) == NULL )
printf( "error opening file \n" );
else
printf( "file opened \n" );
/* Read in characters and place them in "buffer": */
ch = fgetc( fp);
for( i=0; (i < 899 ) && ( feof(fp ) == 0 ); i++ )
{
// store original time in array time
buffer = (char)ch;
*time = buffer;
if (*time < nTmpTime)
{
if (!nTimeFlag)nTimeFlag=1;
else nTimeFlag =0;
}
buffer=*time;
if (nTimeFlag)*time +=12.00;
buffer =*time;
ch = fgetc( fp );
}
printf( "%s\n",buffer);
fclose(fp);
}
Can some one pls help me, or put me in the right direction.
Thanks!!.