problem with the 2D string

This is a discussion on problem with the 2D string within the C Programming forums, part of the General Programming Boards category; hello guys, i was working with some hashing problem where i was suppose to use 2D char string. but i ...

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682

    problem with the 2D string

    hello guys,
    i was working with some hashing problem where i was suppose to use 2D char string. but i have few problem in it. how do i initialize 2D array what i have done is

    Code:
    char string[10][11]= {};
    this tells that its an empty string

    and how do u check that this particular position is empty for example

    Code:
    if(strcmp(string[3]," what comes here")==0)
    any help would be appriciated

    ssharish2005

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1 - You have declared in essence, 10 "strings", 11 characters in length, including the null.
    2 - You can check to see if a "string" is "empty" by simply doing:
    Code:
    if( string[ x ][ 0 ] == '\0' )
    3 - You compare strings to see if they are something, by doing:
    Code:
    if( strcmp( string[ x ], "string to compare too" ) == 0 )
    4 - You can access an individual letter of a given string by doing:
    Code:
    if( string[ whichstring ][ whichletter ] == whatevercharacter )
    Everything in this color is of course optional.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I'd use
    Code:
    if(string[3][0]=='\0')
    or even
    Code:
    if(!string[3][0])
    Kurt

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    thank you very much guys it worked that

    ssharish2005

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > Everything in this color is of course optional.
    Well it would be, if you had != as the test

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Everything is optional. You just have to be asking the right question.
    Notice I didn't complete anything other than 'if'. The 'then' is up to you to pencil in.


    Quzah.
    Hope is the first step on the road to disappointment.

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. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Replies: 4
    Last Post: 03-03-2006, 01:11 AM

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