A function to Clear String.

This is a discussion on A function to Clear String. within the C Programming forums, part of the General Programming Boards category; I Need Clear a String By Function but compiler sends a Warning: Suspicious Pointer Conversion. Code: void SetNull (char **pString){ ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    158

    A function to Clear String.

    I Need Clear a String By Function but compiler sends a Warning: Suspicious Pointer Conversion.

    Code:
    void SetNull (char **pString){
    	int iCont, iLen;
    	
    	iLen = strlen (pString);
    	for (iCont=0; iCont<iLen; iCont++)
    		pString [iCont] = NULL;
    	
    	pString [iCont]	= '\O';
    }
    
    ....
    
    int VcomCmdUser(TCPREADDATA *p)
    { 
            SetNull (&p->ReadUartChar);
    }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,707
    You only need to define it like so

    Code:
    /*
    @param in/out - pcs - string to clear
    Pre-condition: pcs is a writable C-string.
    Post-condition: pcs[0] == '\0'
    */
    void ClearStr ( char * pcs )
    {
       *pcs = '\0';
    }
    as a C-string is any number of characters immediately followed by a zero.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    why char** as parameter type? use char* or dereference pString (*pString)

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    158
    Quote Originally Posted by citizen View Post
    You only need to define it like so

    Code:
    /*
    @param in/out - pcs - string to clear
    Pre-condition: pcs is a writable C-string.
    Post-condition: pcs[0] == '\0'
    */
    void ClearStr ( char * pcs )
    {
       *pcs = '\0';
    }
    as a C-string is any number of characters immediately followed by a zero.
    Goooood!
    Thanks!

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by sergioms View Post
    I Need Clear a String By Function but compiler sends a Warning: Suspicious Pointer Conversion.

    Code:
    void SetNull (char **pString){
        int iCont, iLen;
        
        iLen = strlen (pString);
        for (iCont=0; iCont<iLen; iCont++)
            pString [iCont] = NULL;
        
        pString [iCont]    = '\O';
    }
    
    ....
    
    int VcomCmdUser(TCPREADDATA *p)
    { 
            SetNull (&p->ReadUartChar);
    }
    Huh?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM

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