QUOTE(chris.tkd @ 27 Sep, 2006 - 12:35 PM)

Hey can anyone help me with this problem. Ive to open a file, create a copy of it, and remove all the spaces. I just cant figure out how to remove the spaces. My code is below. Thanks in advance
CODE
#include <stdio.h>
#include <ctype.h>
main()
{
/*create files and char*/
FILE *original;
FILE *copy;
char ch;
/*open input and create output*/
original = fopen("input.txt", "r");
copy = fopen("output.txt","w");
/*while there is data in the file
check if its a space, if it is
dont copy it, else copy it to
the output file*/
while(ch!=-1)
{
ch = fgetc(original);
if(isspace(ch))
{
//Do not print out <--- THIS IS WHERE IM STUCK
}
fputc(ch,copy);
}
/*close open files*/
fclose(original);
fclose(copy);
printf("The copy operation has been complete");
getch();
}
I'm a total beginner so this may be silly.
If you inverted the logic and did this does it work? (I haven't tested it). If you only 'put' when it's NOT a space does it solve your problem?
Apologies if this is a waste of time.
CODE
while(ch!=-1)
{
ch = fgetc(original);
if(!isspace(ch))
{
fputc(ch,copy);
}
}
This post has been edited by janotte: 28 Sep, 2006 - 02:17 AM