I'm writing a C code trying to avoid a blanks in a File. I just want to count one on every occurrence of the concatenated blanks.
For instance, if I have something like this:This is just a test
Whit any blanks like '\n'
, ' '
or \t
between that words. I've tried this:
if( (current_c == ' ') || (current_c == '\t') || (current_c == '\n') ){
blank_counter++;
do{
fgetpos(file, &position);
} while( (fgetc(archivo) == ' ') || (fgetc(archivo) == '\t') || (fgetc(archivo) == '\n') );
fsetpos(file, &position);
\***********************************************
*******This is just debugging block*************
printf("The current char: %c\n", current_c);
fputc(c, file);
************************************************\
}
Like you can notice, the above function is just a part. At the beginning I have the first instruction:while( (current_c = fgetc(file)) != EOF )
And to work with fsetpos()
and fgetpos()
a declarative fpos_t position;
.
I've a little troubles. If you run the code you could get a mistake. When the occurrence is '\n'
, the pointer doesn't recognizes it.
Is there anyone how could help me with that?
转载于:https://stackoverflow.com/questions/53148278/avoiding-the-blank-in-files