How can I create multiple variables in C?

This is a discussion on How can I create multiple variables in C? within the C Programming forums, part of the General Programming Boards category; Currently I have the following, (except many more than just 5 windows). WINDOW *vwin1, *vwin2, *vwin3, *vwin4, *vwin5; vwin1=newwin(0,0,3,0); vwin2=newwin(0,0,3,0); ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    13

    How can I create multiple variables in C?

    Currently I have the following, (except many more than just 5 windows).

    WINDOW *vwin1, *vwin2, *vwin3, *vwin4, *vwin5;
    vwin1=newwin(0,0,3,0);
    vwin2=newwin(0,0,3,0);
    vwin3=newwin(0,0,3,0);
    vwin4=newwin(0,0,3,0);
    vwin5=newwin(0,0,3,0);


    Is it possible to create the above in a for loop? The below doesn't work. I don't know what to use, obviously [i] isn't it. In bash, a simple $i would work.

    Code:
    int i;
    for ( i = 1; i < 6; i++ )
    {
         WINDOW *vwin[i];
         vwin[i]=newwin(0,0,3,0);
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    > WINDOW *vwin[i];
    Put this outside the loop.
    WINDOW *vwin[6];

    Oh, and arrays start at subscript 0, not 1.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can i create a treeview for my global variables?
    By metaldemon in forum Game Programming
    Replies: 1
    Last Post: 10-26-2011, 05:41 AM
  2. Create multiple executables instead of one
    By sridharval in forum C++ Programming
    Replies: 3
    Last Post: 05-01-2010, 09:34 PM
  3. How to create a C project with multiple source files
    By MSF1981 in forum C Programming
    Replies: 5
    Last Post: 03-22-2009, 09:25 AM
  4. Can I dynamically create vectors of multiple depths?
    By 6tr6tr in forum C++ Programming
    Replies: 8
    Last Post: 04-14-2008, 02:47 AM
  5. #Develop Question, How do i create multiple Windows?
    By Zeusbwr in forum C# Programming
    Replies: 0
    Last Post: 04-24-2005, 11:14 AM

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