Thread: Question on how to remove all non-characters in string

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    14

    Question on how to remove all non-characters in string

    I'm making this Palindrome recursion program, and capitals are changed to lower case, and all blanks and punctuation must be ingnored. I've tested all my other functions and they work, except for the one that removes the blanks and punctuation.

    Code:
    void Cleanup_String(char *stringptr1)
    {
    	char *stringptr2 = stringptr1;
    	char *debugptr		 = stringptr1;
    	
    
    	for(; *stringptr1 != '\0'; stringptr1++)
    	{
    		*stringptr1 = tolower(*stringptr1);
    	}//checked
    
    	
    
    	for(; stringptr2 != '\0'; stringptr2++)
    	{
    		if ( !(isalpha (*stringptr2) ) )
    		{
    			for( char * temptr = stringptr2; temptr != '\0'; temptr++)
    			{
    				*temptr = *(temptr+1);
    			}
    		}
    	}				//Error in this whole loop
    
    	
    	cout << debugptr << endl;
    
    	cout << "Finished loop." << endl;
    	return;
    }
    The first for loop makes everything lowercase, but the 2nd for loop group is supposed to clear out the spaces and puncuation by moving the string down an index to overwrite the space or puncuation, but it isn't working and I was wondering if I'm not using isalpha correctly. I would think the syntax for the whole looping proccess is correct.. Also, for some reason, when I run the program, it enters that function, but never quits it, I just get the "Enter any key to end this program."

    Thanks.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    <jingle> One of these for loops aren't the same... </jingle>

    >> for(; *stringptr1 != '\0'; stringptr1++)
    >> for(; stringptr2 != '\0'; stringptr2++)
    >> for(; temptr != '\0'; temptr++)

    HINT: first one is correct.

    gg

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    14
    Gah, I'm so stupid. Such a stupid mistake. >_<

    Thanks. *looks like a fool now*

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Just think though, it'll be a long time before you're burned badly by that one again.


    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. I'm not ask for ENTIRE program, only 1 Question !
    By Th3-SeA in forum C Programming
    Replies: 10
    Last Post: 10-01-2003, 12:33 PM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. Replies: 2
    Last Post: 05-05-2002, 01:38 PM