Thread: Arrays

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Talking Arrays

    Hello everyone;

    I have a program with a number of constant arrays defined in the header file.

    array1[10] = { .. };
    array2[13] = { .. };

    When I use the code:

    do {

    PrintString(listbase, array1[i]);
    i++;

    } while(array1[i+1] != NULL);

    PrintString() is a function I created in to print the info to the screen in OpenGL and listbase is related to the font. But when it prints it will also print array2[]. So my question is is how can I get my array to print without using a for loop so I can go back and play with my arrays without having to change too much code?
    "If at first you do succeed try not to look astonished!" -- anon

  2. #2
    Razzer
    Guest

    Lightbulb

    What are you trying to do? It looks like you have some type array when you begin, but down when you show some code it looks completely different. It looks, down at the code, like the array is actually an array of strings. Which is it?

  3. #3
    Music_Man
    Guest

    Arrays

    Hello Everyone;

    There seems to be a little confusion in my post so I'll make it clear. I have TWO ARRAYS (array_1[10] and array_2[13]). I want my print function to print array_1[i] until it reaches the end of the array and I should be able to do this by stating:

    do {

    ... //print array_1 element i
    i++;

    while(array_1[i+1] != NULL);

    However, my DO prints all elements of both arrays array_1[] and array_2[], not just array_1[].

  4. #4
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Two things... let's see you're PrintString function, and what are the types of those arrays? Are they null-terminated?

  5. #5
    Music_Man
    Guest

    Reply to BMJ

    Hello BMJ;

    Firstly; all the arrays are null terminated.

    Here is the print function:

    void PrintString(unsigned int base, const char *str) {

    if ((base == 0) || (str == NULL))
    return;

    glPushAttrib(GL_LIST_BIT);
    glListBase(base - 32);
    glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
    glPopAttrib();
    }

    base is the font base (for OpenGL programming)
    str is ths string passed to the function

  6. #6
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Have you looked at the tutorials on nehe.gamedev.net for printing to the screen in OpenGL? They will probably answer this for you...
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM