How do I delete the content of a char && string ??

This is a discussion on How do I delete the content of a char && string ?? within the C Programming forums, part of the General Programming Boards category; Well I'd like to know how I can delete the content of a string... As an example Code: #include <stdio.h> ...

  1. #1
    Registered User client's Avatar
    Join Date
    May 2002
    Posts
    12

    Question How do I delete the content of a char && string ??

    Well I'd like to know how I can delete the content of a string...

    As an example

    Code:
    #include <stdio.h>
    void main(void)
    {
       char string[1][32] = "This is a string";
       char character[1][1] = 'A';
    
       printf("%s, %c", string[1], character[1][1]);
    }
    If I have written a code as the one above, but want to delete the content so that it is again "(null)"

    What do I have to do for a character and a string ???
    Is there a some kind of strdelete command ???

    Thanks in advance
    client
    ---
    client
    "Unfortunately, no one can be told what the C/C++ is... You have to see it by yourself !"
    taken from Programming lesson no. 7

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    See memset(). You can also set the first character of the string to \0.

    Note: You are accessing an index out of range. Should be:

    printf("%s, %c", string[0], character[0][0]);

    not

    printf("%s, %c", string[1], character[1][1]);

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    or, you could just set the first elements to null.

    char string[1][0] = '\0';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Delete char from string?
    By samuelmoneill in forum C Programming
    Replies: 8
    Last Post: 04-24-2009, 03:08 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  4. String Class Operations
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2003, 02:29 PM

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