Return to Snippet

Revision: 23146
at January 31, 2010 13:47 by sebastianf


Updated Code
/* writes one word per line*/

#include <stdio.h>

#define YES 1
#define NO 0

int main (int argc, const char * argv[]){
	int c, nl, INWORD;
	INWORD = NO;
	nl='\n';	
	while((c=getchar())!=EOF){
		if(INWORD==YES){		
			if (c=='\n' || c=='\t' || c==' ') {
				putchar(nl);
				INWORD=NO;
				c=getchar();
				}
			else {
				putchar(c);
				c=getchar();
			}
		}
		else {
			if (c=='\n' || c=='\t' || c==' ') {
				c=getchar();
			}
			else{
				INWORD=YES;
				putchar(c);
				c=getchar();
			}
		}
	}		
}

Revision: 23145
at January 31, 2010 13:05 by sebastianf


Initial Code
/* writes one word per line*/

#include <stdio.h>

#define YES 1
#define NO 0

int main(int argc, const int *argv){
	int c, nl, INWORD;
	INWORD = NO;
	nl='\n';	
	while((c=getchar())!=EOF){
		if(INWORD==YES){		
			if (c=='\n' || c=='\t' || c==' ') {
				putchar(nl);
				INWORD=NO;
				c=getchar();
				}
			else {
				putchar(c);
				c=getchar();
			}
		}
		else {
			if (c=='\n' || c=='\t' || c==' ') {
				c=getchar();
			}
			else{
				INWORD=YES;
				putchar(c);
				c=getchar();
			}
		}
	}		
}

Initial URL

                                

Initial Description

                                

Initial Title
one word per line

Initial Tags

                                

Initial Language
C