K&R Exercise 1-9 (C)

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

    #include    
    main()
    {
        int CurrentChar, LastChar;
        LastChar = '1';
        while ((CurrentChar = getchar()) != EOF)
        {
            if (CurrentChar != ' ')
            {
                putchar(CurrentChar);
                LastChar = '1';
            }
            else
            {
                if (LastChar != ' ')
                {
                    putchar(CurrentChar);               
                    LastChar = ' ';
                }                   
            }   
        }
    }
    

提交回复
热议问题