wanna to kill something

This is a discussion on wanna to kill something within the C Programming forums, part of the General Programming Boards category; i need help!! i need a function that takes a string as a paramter eg "\n\nThis is a \t\ttest" and ...

  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, 01:13 PM
  2. Kill Signal Number? - Help !
    By brett in forum C Programming
    Replies: 5
    Last Post: 06-20-2007, 04:39 AM
  3. RePhrase: Wanna join a DEV team?
    By Kilo in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-01-2005, 07:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21