Global Arrays

This is a discussion on Global Arrays within the C Programming forums, part of the General Programming Boards category; I need to initialize a global array whose length is to be determined by a command line parameter. Any help ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    1

    Global Arrays

    I need to initialize a global array whose length is to be determined by a command line parameter. Any help would be appreciated.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There ain't no such a thing as "a global array whose length is to be determined". (There are variable-length arrays in C99, but they must have block scope.) If you actually have to have a global array (10-to-1 says you don't, but it just may be possible that you do), you'll have to declare a pointer to whatever-type-is-in-your-array, and then allocate the memory later, once you've processed the command-line parameter.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    If I assume there is already an array, then
    Something like this??

    -------
    Read length
    convert to int
    for 0 to length
    array[i] = 0
    Last edited by mcha; 02-03-2008 at 05:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global arrays shared between multiple source files
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 08-14-2008, 06:29 PM
  2. Dyanmic Arrays - Global?
    By Greatgraddage in forum C Programming
    Replies: 14
    Last Post: 01-09-2007, 07:58 AM
  3. OOP and global arrays
    By dan20n in forum C++ Programming
    Replies: 3
    Last Post: 02-24-2005, 11:10 PM
  4. How to declare global arrays of unknown length?
    By ajm218 in forum C Programming
    Replies: 3
    Last Post: 08-07-2003, 09:13 AM
  5. global arrays ???
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 06-13-2002, 01:05 PM

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