Well I rewrote my code to use your much neater nicer version Prelude, I also did what you suggested and counted the spaces inorder to put the brackets where i wanted them.
So far so good
Now, inorder to put the fullstop after the number at the beggining of each line i thought i would place a '.' after each digit and add a counter so that if the char got from the orginal file was the second digit on a given line it would place it over the character previously written (which would be a '.')
IE. it would get a '1' print it to file, then print a '.' to file, the if it got another number, say a '0', it would place it over the '.' just written and then put another '.'
So that i wouldn't get "1.0.", and instead have "10."
Thing is I thought i could just subtract 1 from the file pointer....... didn't work.
My code is:
Instead of getting "10." i get "1..", which remains the same if i change the pointer to outfile-2. IE. the second digit which should be printing over the first '.' isn't printing at all.
int main ()
FILE *infile, *outfile;
int x, f, c=0;
if ( ( infile = fopen ( "results.txt", "r" ) ) != NULL &&
( outfile = fopen ( "modresults.txt", "w" ) ) != NULL )
while ( ( f = fgetc (infile) ) != EOF )
fputc ( ')' , outfile );
fputc ( ',' , outfile );
fputc ( ' ' , outfile );
case ' ':
fputc ( f , outfile );
if ( ++x == 3 ) fputc( '(', outfile );
if (c++ == 1)
fputc ( f, outfile-1); /* problem line*/
else fputc( f, outfile);
fputc ( '.', outfile);
fputc ( f, outfile );
fclose ( infile );
fclose ( outfile );
fprintf ( stderr, "Error: File open failure\n" );
EDIT: Ah, solved it, found the fseek() function. All working as planned now. Thanks for your help Prelude.