Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*write a program which copies its input to output and replaces
- each string of multiple blanks by one blank*/
- #include <stdio.h>
- #define IN 1
- #define OUT 0
- int main ()
- {
- int c, b, z; //c searches the chars, b goes IN on the first space,
- //z will be used to make it work for more than one space
- b = OUT;
- z = OUT; //beginning of the loop, both are set to zero
- while ((c = getchar()) != EOF) //we search all the chars
- if (c == ' ')
- ++b; //If c picks up a space we set b to IN, starting the first loop
- while (b == IN) //first loop
- {
- if (c == ' ') //if the char after the first space is another space we
- // start the second loop by setting z to IN
- {
- b = OUT;
- z = IN;
- }
- if (z == IN) //second loop
- {
- if (c == ' ') //if we find another space in the second loop we
- b = IN; //start the first loop again
- }
- else printf("%c, c"); //if we dont find a space we print the char
- printf("%c, c"); //I guess this prints all the chars that are not spaces??
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement