Thread: String Problem

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187

    String Problem

    creation of *text[] =
    char* text[9][201]={
    "This is a test",
    "t3.",
    "hi."
    };

    alltext is described as : char *AllText[1][1];

    in constructor : (passed *text[])

    for(int i=0; i<vlen; i++){
    AllText[i][0]=new char[slen+1];
    strcpy(AllText[i][0], text[i]);
    cout<<AllText[i][0]<<endl;
    }


    In the display function :
    for(int i=0; i<vlen; i++)
    cout<<AllText[i][0]<<endl;


    -------------------------------------------
    OUTPUT:
    This is a test
    t3.
    hi.

    This is a test
    xxx - crash here - xxx
    ---------------------------------------------


    **CRASH WHEN GOING TO AllText[1][0]**
    (first line prints fine)

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Try increasing the array size:

    Code:
    char *AllText[9][1];

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    AllText[1][1];


    is an array with exactly one field: AllText[0][0].

    The numbers in brackets are supposed to give the arrays size. If you want it to contain 2x2 fields, it should be AllText[2][2].
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  5. Replies: 4
    Last Post: 03-03-2006, 02:11 AM