Originally Posted by
fsx
Code:
while((c = getchar()) != EOF)
{
if((c == ' ') || (c == '\t'))
putchar('\n');
What you really want is a "nop" (no-op, no operation) and to continue --
Code:
if((c == ' ') || (c == '\t'))
continue;
Except you still need a line break! So maybe
Code:
#include <stdio.h>
int main(void)
{
int c;
char flag=0;
while((c = getchar()) != EOF)
{
if((c == ' ') || (c == '\t'))
if (flag) continue;
else { putchar('\n');
flag=1; }
else { putchar(c);
flag=0; }
}
return 0;
}
If you are just on chapter 1 you may not know about "continue" (it just starts the loop again without doing anything else).
The use of a flag is a very handy, basic, chapter 1 kind of thing, so if you don't understand what that's about, try to, or ask and I'll explain.
Basically now you could type:
Code:
this is a sentance with extra spaces
Output:
this
is
a
sentence
with
extra
spaces