Thread: 2d strings and setting to null

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    37

    2d strings and setting to null

    If an array
    Code:
    char firstName[5][20] = {' '};
    in the program you give firstName[0] = name by a scanf statement.

    Now, I need to reset firstName [0][0] = all null.

    How do I do this?

    Code:
    firstName[index][0] = NULL;
    This is what I have right now. If I do a printf to check it it prints out as "NULL".

  2. #2
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    I m confused. sorry.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    Um, lets see....
    the string char firstName[5][20]={' '};
    So every space in the string is null character.

    through a scanf statement later on I give firstName[0][0] the name of Bob.

    Now I need to bring the value of firstName[0][0] back to all null characters.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Now I need to bring the value of firstName[0][0] back to all null characters.
    All nul or just the first one?

    firstName[0][0] = '\0';

    so firstName[0] would look like, "\0ob\0 "

    Is that what you're trying to achieve, or you want to set all of firstName[0] to nul, which could be:
    Code:
    memset(firstName[0], '\0', sizeof(firstName[0]));

  5. #5
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Fox101 View Post
    Um, lets see....
    the string
    Code:
    char firstName[5][20]={' '};
    So every space in the string is null character.
    I am not very much sure about this but maybe you are right.

    through a scanf statement later on I give firstName[0][0] the name of Bob.
    firstName[0][0] can hold only a single character. 'Bob' is three characters long.

    Now I need to bring the value of firstName[0][0] back to all null characters.
    Code:
    firstName[0][0]='\0';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of strings and memory allocation
    By maluyk in forum C Programming
    Replies: 7
    Last Post: 01-26-2009, 11:52 AM
  2. Setting strings
    By LloydUzari in forum C++ Programming
    Replies: 15
    Last Post: 07-30-2004, 04:59 PM
  3. setting msvc 6 to use unicode strings
    By reanimated in forum Windows Programming
    Replies: 6
    Last Post: 01-03-2004, 10:08 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM