Saturday, May 22, 2010

For the following C-program, does it mean it prefers to be in the state of "not inspace" or putting out chars?

#include %26lt;stdio.h%26gt;





int main(void)


{


int c;


int inspace;





inspace = 1;


while ((c = getchar()) != EOF)


{


if (c == ' ' || c == '\t' || c == '\n')


{


if (inspace == 0)


{


inspace = 1;


putchar('\n');


}


/* else, don't print anything */


}


else


{


inspace = 0;


putchar(c);


}


}





return 0;


}

For the following C-program, does it mean it prefers to be in the state of "not inspace" or putting out chars?
There is no preference in the software - that concept doesn't apply.





What the program does is to replace white space (1 or more of space, tab or newline) and replace it with a single new line. In other words, the software will copy each word of the input on its own line in the output.


No comments:

Post a Comment