标签:c语言
#include <stdio.h> int main(void) { int c; int inspace=0; while((c = getchar()) != EOF) { if(c == ' ') { if(inspace == 0) { inspace = 1; putchar(c); } } else { inspace = 0; putchar(c); } } return 0; }
#include < stdio.h > main ( void ) { int c; int number; number = 0; //initialization space numbers while ( ( c = getchar() ) != EOF ) { if ( c == ' ' ) { ++number; if ( number == 1 ) putchar( c ); } if ( c != ' ' ) { putchar( c ); number = 0; } } return 0; }
#include < stdio.h > main ( void ) { int c; while ( ( c = getchar() ) != EOF ) { if ( ' ' == c ) { putchar ( c ); while ( ( c = getchar() ) == ' ' && c != EOF ) ; } if ( EOF == c ) break; putchar ( c ); } return 0; }
#include <stdio.h> int main() { int c, pc; pc = EOF; while ((c = getchar()) != EOF) { if (c == ' ') if (pc != ' ') putchar(c); if (c != ' ') putchar(c); pc = c; } return 0; }
C语言K&R习题系列——句子中一个空格代替多个空格的四种方法
标签:c语言
原文地址:http://blog.csdn.net/u011694809/article/details/46120777