Thread: wanna to kill something

  1. #1
    Unregistered
    Guest

    Angry wanna to kill something

    i need help!! i need a function that takes a string as a paramter
    eg
    "\n\nThis is a \t\ttest"

    and turns it into this:

    "This is a test"

    this is beyond me at the moment and it just won't work can anyone help?

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    34
    Here is a function that will do what you need.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void RemoveWhiteSpace(char *p);
    
    int main(void)
    {
    	char str[51];
    
    	strcpy(str, "Remove\t\tall  white space\n and new lines\t\n");
    	RemoveWhiteSpace(str);
    	printf("(%s)\n", str);
    
    	strcpy(str, " \t\n");
    	RemoveWhiteSpace(str);
    	printf("(%s)\n", str);
    
    	strcpy(str, "");
    	RemoveWhiteSpace(str);
    	printf("(%s)\n", str);
    
    	return 0;
    }
    
    void RemoveWhiteSpace(char *p)
    {
       char *t;
    
       while (*p)
       {
            // modify this line to include other characters to remove
            if (*p == '\t' || *p == '\n')
            {
                t = p;	// use temp pointer to skip over all selected characters
    
                while (*t)
                {
                       *t = *(t + 1);
                        t++;
                }
            }
            else
            {
                p++;
            }
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to kill a dragon with various programming languages
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-01-2007, 12:13 PM
  2. Kill Signal Number? - Help !
    By brett in forum C Programming
    Replies: 5
    Last Post: 06-20-2007, 03:39 AM
  3. RePhrase: Wanna join a DEV team?
    By Kilo in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-01-2005, 06:42 PM