Thread: Collapse spaces

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    Have you attempted to write this yourself? We are not here to write the code for you.

    Make an attempt to write this yourself, then if you have questions or problems, post your code, and we can give you advice.

    Please read the Forum Rules FAQs before posting here.

    Was this an assignment from an Instructor, or from a book, or online tutorial?
    Last edited by rstanley; 10-11-2020 at 05:22 AM.

  2. #2
    Registered User
    Join Date
    Oct 2020
    Posts
    2
    Quote Originally Posted by rstanley View Post
    Have you attempted to write this yourself? We are not here to write the code for you.

    Make an attempt to write this yourself, then if you have questions or problems, post your code, and we can give you advice.

    Please read the Forum Rules FAQs before posting here.
    I did not mean to make it look like I just want someone to do my task, I just need some help. I wrote this so far:
    Code:
    #include <stdio.h>
    #include <ctype.h>
    int collapseSpaces{
         int c1=getchar();
         int c2=getchar();
         while(isspace(c1) && issspace(c2)){   // my logic here was that I'd check if two consecutive characters are both spaces and if it is true, I'd replace them with a single space character
                 c1=c2=' ';
         }
    int main()
    {
    return 0;
    }

    I've also created a .txt file (I work in putty), in order to write some text to check if the program is working. As I stated above, I also need some help understanding how to print the modified text in main. Also I don't fully understand the newline part of the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I allow spaces on a cin?
    By boblablabla in forum C++ Programming
    Replies: 10
    Last Post: 12-09-2009, 02:05 PM
  2. Replies: 7
    Last Post: 10-03-2009, 10:58 PM
  3. Getting rid of spaces in C
    By Poincare in forum C Programming
    Replies: 2
    Last Post: 01-23-2009, 03:08 PM
  4. set spaces in Tab.
    By nilrac in forum C Programming
    Replies: 8
    Last Post: 11-14-2002, 01:58 PM

Tags for this Thread