K&R Exercise 1-9 (C)

后端 未结 30 1116
北荒
北荒 2021-01-31 19:46

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

I\'m assuming by thi

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 20:21

    /*a program that copies its input to its output, replacing each string of one or more blanks by a single blank*/
    
    #include 
    #include
    
    int main(void)
    {
        double c;
        char blank = ' ';
    
        while((c = getchar()) != EOF)
        {
            if(c == ' ')                                
                {
                putchar(c);                             
    
                    while(( c = getchar() )== ' ')      
    
                        {
                        if(c != ' ')                    
                        break;
                        }
                }
    
    
    
    
            if(c == '\t')                               
                {
                    putchar(blank);                     
                        while((c = getchar()) == '\t')  
    
                        {
                        if(c != '\t')                   
                        break;
                        }
                }
    
        putchar(c);                                     
        }
    
    return 0;
    }
    

提交回复
热议问题