字符替换

1. 连续空格用一个空格替换

2. 制表符用 替换,换行符用 替换,反斜杠用\替换

#include <stdio.h>
#include <Conio.h>
main(){
      int input;
      while((input=getchar())!=EOF){
         if(input == '
'){
                     printf("\n");
                     printf("
");
                     continue;
                  }
         if(input == ' '){
                     while((input=getchar())==' '){
                                                   continue;
                                                }
                     if(input == '
'){
                         printf(" \n");
                     }else putchar(' ');
                  }
         if(input == '	'){
                     printf("\t");
                     continue;
                  }
         if(input == '\'){
                     printf("\\");
                     continue;
                  }
         putchar(input);
      }
      getch();
}

tips:

如果想要打印退格符,就要把input=getchar()换成input=getch(),前者是有缓存的,退格符会直接起作用而不会打印。

原文地址:https://www.cnblogs.com/ryansunyu/p/4495211.html