Try this, instead of using a counter you use two reader variables, one to read the actual variable and one to test the next one and see if it's valid for the operation. Each time you read the whisker variable(whisker means it's feeling forward ), you test it for a space, if it's not space then you test it for EOF, if that's false too then you've got a valid character. Don't forget to ungetc() the whisker variable after that so that ch can read everything in order and you don't miss a character.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE *in, *out;
int ch, chWhisker;
char name[80];
if (argc < 2){
fprintf(stderr, "Usage: %s filename\n",argv[0]);
exit(1);
}
if ((in = fopen(argv[1], "r")) == NULL){
fprintf(stderr, "I couldn't open the file \"%s\"\n",argv[1]);
exit(2);
}
strcpy(name, argv[1]);
strcat(name, ".fnl");
if ((out = fopen(name, "w")) == NULL){
fprintf(stderr, "Can't create output fule.\n");
exit(3);
}
while ((ch = getc(in)) != EOF){
if (ch != " " && (((chWhisker = getc(in)) != " ") != EOF)){
ungetc(chWhisker);
putc(ch, out);
if (fclose(in) != NULL || fclose(out) != NULL)
fprintf(stderr, "Error in closing files\n");
}
return 0;
}