Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 748 Bytes

exercise1-9.md

File metadata and controls

37 lines (30 loc) · 748 Bytes

Exercise 1-9

Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.

Process

Another simple one

Count amount of blanks in a sequence, then reset. If sequence is below 1, print current character

Final Code

#include <stdio.h>

int main(){
	int c;
	int spaceCount = 0;
	
	while((c = getchar()) != EOF){
		if (c == ' ')
			++spaceCount;
		else
			spaceCount = 0;
		
		if (spaceCount <= 1)
			putchar(c);
	}
	return 0;
}

Output

output for exercise1-8

output for exercise1-8

Back to Main