Re: exercise 1-20 K&R
- From: "Robert Gamble" <rgamble99@xxxxxxxxx>
- Date: 10 Jun 2006 09:56:18 -0700
Aenima1891 wrote:
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 main (void) is preferred.
{
int counter, c;
while ((c = getchar()) != EOF) {
if (c == '\t') {
for (counter = 1; counter <= TABSIZE; ++counter)
putchar(' ');
This doesn't accomplish the goal of the exercise which is to replace
the tab with the number of spaces needed for the *next* tab stop, that
is, the next multiple of TABSIZE characters. Your version always
prints TABSIZE spaces which will only be the right thing to do when the
tab character is encountered immemdiately after a tab stop.
}
else
putchar(c);
}
return 0;
}
what do you think about this??
Robert Gamble
.
- References:
- exercise 1-20 K&R
- From: Aenima1891
- exercise 1-20 K&R
- Prev by Date: Re: assignment from incompatible pointer type
- Next by Date: Re: about the #pragma
- Previous by thread: exercise 1-20 K&R
- Next by thread: Re: exercise 1-20 K&R
- Index(es):
Relevant Pages
|