把文件内的0替换成0+空格

C代码:
#include<stdio.h>
#include<stdlib.h>

int main()
{
    char c;
    do{
        c=getchar();
        switch(c){
            case '0' :
                putchar(c);
                putchar(' ');
                break;
            default:
                putchar(c);
        }
    }while(c!=EOF);
    return 0;
}

C#代码:
using System;
class Lab20{
    static void Main(){
        int x;
        char c;
        while(true){
            x = Console.Read();
            if(x ==-1){
                break;
            }
            c = Convert.ToChar(x);
            switch(c){
                case '0':
                    Console.Write(c);
                    Console.Write(' ');
                    break;
                default:
                    Console.Write(c);
                    break;
            }
        }
    }
}

命令: Lab < input.txt > output.txt
利用操作系统的输入输出重定向功能

方法三:用Linux下的一条命令即可
sed ‘s/0/0 /g’input.txt > output.txt

把文件内的每个字符后面均添加一个空格
http://blogold.chinaunix.net/u2/68904/showart_695390.html
sed ‘s/./& /g’input.txt > output.txt
sed ‘s//(./)//1 /g’input.txt > output.txt

你可能感兴趣的:(c,linux,C#,System,Class)