exercise 1-20 K&R



write a program that replaces strings of blanks by the minimum number
of blanks to space to the next tab stop.

#include <stdio.h>
#define TABSIZE 8


int main()
{
int counter, c;

while ((c = getchar()) != EOF) {
if (c == '\t') {
for (counter = 1; counter <= TABSIZE; ++counter)
putchar(' ');
}
else
putchar(c);
}
return 0;
}

what do you think about this??

.



Relevant Pages

  • Re: K&R2 ex 1-8
    ... and it's best to use more blanks (after commas and around ... int main ... If an "if" or other control statement controls only a single ... the braces associated with the "while" are unnecessary. ...
    (comp.lang.c)
  • Re: Remove extra blanks
    ... blanks in a string by a single blank. ... int sglspc{ ... As part of a real program, ...
    (comp.lang.c)
  • Re: Remove extra blanks
    ... blanks in a string by a single blank. ... int main ... Notice the absence of string buffers. ... static void deblank(char *d, const char *s) ...
    (comp.lang.c)
  • Re: Remove extra blanks
    ... blanks in a string by a single blank. ... int main ... Notice the absence of string buffers. ... string - it is therefore not the excercise to simplify the algorithm ...
    (comp.lang.c)
  • Re: Remove extra blanks
    ... blanks in a string by a single blank. ... int main ... Notice the absence of string buffers. ... string - it is therefore not the excercise to simplify the algorithm ...
    (comp.lang.c)