Week045

SkipSpacesNotReady

Apr 13th, 2022 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. void skipspaces(FILE* f)
  2. {
  3.     if (!f) return;
  4.     rewind(f);
  5.     fpos_t start, end, mainstart;
  6.     char s;
  7.     int count;
  8.     while (!feof(f))
  9.     {
  10.         count = 0;
  11.         while ((s = fgetc(f)) && s != ' ' && !feof(f) && s != '\n');
  12.         if (feof(f)) return;
  13.         fgetpos(f, &mainstart);
  14.         start = mainstart;
  15.         while ((s = fgetc(f)) && s == ' ' && !feof(f)/* || s == '\n'*/) count++;
  16.         if (feof(f)) return;
  17.         fseek(f, -1, SEEK_CUR);
  18.         fgetpos(f, &end);
  19.         if (count > 0)
  20.         {
  21.             while (!feof(f))
  22.             {
  23.                 fsetpos(f, &end);
  24.                 s = fgetc(f);
  25.                 if (s == EOF) break;
  26.                 fsetpos(f, &start);
  27.                 fputc(s, f);
  28.                 start++; end++;
  29.             }
  30.             fsetpos(f, &mainstart);
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment