Thread: clearing cstring

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    clearing cstring

    Over a futuremark someone asked how to clear a cstring.
    Somone replied use strcpy()
    another replied use memset()
    i suggested *cString='\0';

    what is the perfered method for clearing a cstring?

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    An empty string is represented by pointer to null character.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    clear it to what. Spaces, or null characters?
    one would be
    Code:
    for(x=0;x<strlen(string);x++){
         array[x]='\0';
    }
    or if it is a pointer.
    Code:
    pointerarray=NULL;

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    I think he means clear as in destroy, erase, incinerate or make-so-it's-lengt-wold-be-0.

    EDIT: linuxdude, why wold anyone want to fill entire string with null characters?

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >i suggested *cString='\0';
    That would be my choice, unless of course the programmer is trying to destroy the data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Writing CObjects with Serialization to CArchive
    By ruben_gerad in forum C++ Programming
    Replies: 0
    Last Post: 11-09-2006, 08:25 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM
  5. Replies: 2
    Last Post: 11-08-2002, 03:22 AM