Thank you so much! Now it skips the the white spaces, but I seem to be having trouble with lines that have less than 21 characters on it. ><
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void){
FILE* sp1;
FILE* sp2;
int curCh; // variable 1
int preCh; // variable 2
int countCh = 0; // variable 3;
int whiteSpace = 0; // var4
int closeStatus;
printf("File copy has started\n");
if (!(sp1 = fopen ("FILE1.DAT", "r"))){
printf("Error opening FILES1.DAT for reading");
return (1);
}//if open
if (!(sp2 = fopen ("FILES2.DAT", "w"))){
printf("Error opening FILES2 for writing");
return (2);
}
while ((curCh = fgetc(sp1)) != EOF){
if (curCh != ' '){
whiteSpace = 0;
countCh++;
}
// this is where I'm having the problem
if(curCh == '\n'){
if (countCh < 21 && whiteSpace !=0 ){
fputc (preCh, sp2);
fputc (' ', sp2); }
countCh = 0;
}
whiteSpace = 1;
if ( countCh == 21 ){
fputc(curCh, sp2);
fputc (' ', sp2);
}
preCh = curCh;
}
fputc ('\n', sp2);
fclose(sp1);
closeStatus = fclose(sp2);
if (closeStatus == EOF)
{
printf("File close error.\a\n");
return 201;
} // if close error
printf("File successfully created\n");
system ("pause");
return 0;
}