Thread: creating variables on the fly?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    26

    creating variables on the fly?

    Here is the situation. I need to load a list of text into a listbox. I have a text file that has the list in this format:

    item1
    item2
    item3

    I than open this text file and load everything into a character array. Now I need to put these items into a listbox. However when I do that, it puts all items as if it were one, so the list box has one line that goes:

    item1item2item3

    I need to somehow create different character arrays on the fly so that I can store one item in each array so that when I go to add them to the list box, it adds them seperatly. I'm using LB_ADDSTRING

    Hope that makes some sense.

    Thanks.

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    114
    Do you really need to allocate variables for each? I don't know how to use the listbox but I would think you would do somthing like this:

    Code:
    char buffer[100];
    
    while (fgets(buffer,sizeof(buffer),fp) != NULL);
        add_to_list_box(buffer);
    Cya

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    26
    Quote Originally Posted by kzar
    Do you really need to allocate variables for each? I don't know how to use the listbox but I would think you would do somthing like this:

    Code:
    char buffer[100];
    
    while (fgets(buffer,sizeof(buffer),fp) != NULL);
        add_to_list_box(buffer);
    Cya
    Oye! It works, I didn't know about fgets, reads things one line at a time. Learn something new every day.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 12:02 PM
  3. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  4. static variables
    By Luigi in forum C++ Programming
    Replies: 4
    Last Post: 04-24-2003, 07:13 PM
  5. creating accelerators on the fly
    By bennyandthejets in forum Windows Programming
    Replies: 2
    Last Post: 12-15-2002, 11:19 PM