K&R Exercise 1-9 (C)

后端 未结 30 1109
北荒
北荒 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:19

    I worked really hard at finding a solution that used only the material that has already been covered in the first part of the first chapter of the book. Here is my result:

    #include 
    
    /* Write a            program         to copy its input to       its output, replacing             each string of one         or more blanks by a single blank. */
    
    main()
    {
        int c;
    
        while ((c = getchar()) != EOF){
            if (c == ' '){
                putchar(c);
                while ((c = getchar()) == ' ')
                    ;
            }
            if(c != ' ')
                putchar(c);
        }
    }
    

提交回复
热议问题