Space Deletion

  1. Consider the following code which prints out the length of each input line (excluding the newline character).
    
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
        int len;
        const int MAX_LEN = 20;
        char s[MAX_LEN];
        char* p;
        while ( cin.getline(s, MAX_LEN) )
        {
            for(p = s; *p != '\0'; p++)
                ;
            cout << p - s << endl;
        }
        return 0;
    }
    
    
  2. Modify the program so that it will delete the spaces in each input string and print it out.
  3. The program may run as follows.
    
    This is a book.
    Thisisabook.