dear guru's,
I had a problem in C, and i seems i can't figure out why this piece of codes seems not working properly, kindly help my with my little problem?
/* My problem here is, how can i copy the file into other file name, i just wanted to copy them eliminate the leading spaces leaving only one space each and every after word. Kindly help me figure out what type of condition can i use here?
ex:
from: have' '' '' 'a' '' 'nice' '' '' '' 'day.
to: have a nice day.
*/
================================================== ==
code starts here:
================================================== ==
/* Copying a file and eliminate white spaces and tab. */
#include <stdio.h>
#include <stdlib.h>
int file_copy( char *oldname, char *newname );
main()
{
char source[80], destination[80];
/* Get the source and destination names. */
printf("\nEnter source file: ");
gets(source);
printf("\nEnter destination file: ");
gets(destination);
if ( file_copy( source, destination ) == 0 )
puts("Copy operation successful");
else
fprintf(stderr, "Error during copy operation");
return(0);
}
int file_copy( char *oldname, char *newname )
{
FILE *fold, *fnew;
int c,b,col;
/* Open the source file for reading in binary mode. */
if ( ( fold = fopen( oldname, "r" ) ) == NULL )
return -1;
/* Open the destination file for writing in binary mode. */
if ( ( fnew = fopen( newname, "w" ) ) == NULL )
{
fclose ( fold );
return -1;
}
/* Read one byte at a time from the source; if end of file */
/* has not been reached, write the byte to the */
/* destination. */
while (1)
{
c = fgetc( fold );
/* My problem here is, how can i copy the file into other file name, i just wanted to copy them eliminate the leading spaces leaving only one space each and every after word. Kindly help me figure out what type of condition can i use here?
ex:
from: have' '' '' 'a' '' 'nice' '' '' '' 'day.
to: have a nice day.
*/
if ( !feof( fold ))
fputc(c,fnew );
}
fclose ( fnew );
fclose ( fold );
return 0;
}
================================================== ==
code ends here:
================================================== ==
thank you,
j