Thread: Loop output is not quite what I want

  1. #16
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You're still implementing a second loop, which is unnecessary and again, over complicates things.

    My last post gave you all the code necessary to remove duplicate chars (including spaces).

    You should simplify your code before moving on, or you will find it more confusing later on.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  2. #17
    Registered User
    Join Date
    Oct 2002
    Posts
    32
    Sometimes I just need a hit to the head.

    It does work and it does remove reapeating characters and extra white spaces from the space bar but I could not get it to remove extra spaces due to tabs
    Code:
    do	
    	{
    		//Read input data 1 character at at time 
    
    		while((current = cin.get()) != '/n')
    		{
    			if(current != previous)
    			{
    				cout << current;
    				previous = current;
    			}
    		}
    
    		cout << endl << endl;
    		
    	}	while(current == '\n');
    	return 0;
    }
    That is why I went to the other code. I handled the words white spaces and tabs but I would have to add to it to remove the repeating characters. I have tried to add
    Code:
    if(previous == '\t' && current != ispace(current)) 
    {
          putchar(' ');
    }
    I just cant figure out how to get rid of unwanted tabs this way. Any suggestions?
    Last edited by Zalbik; 10-30-2002 at 09:51 PM.

  3. #18
    Registered User
    Join Date
    Oct 2002
    Posts
    32
    I think I got! I'll be testing it when I get home.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-01-2008, 10:09 AM
  2. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. OUTPUT TO PRINTER using c++ ???
    By howhy in forum C++ Programming
    Replies: 12
    Last Post: 09-01-2005, 09:36 PM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:13 AM