Thread: INTs for array size

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    Unhappy INTs for array size

    If I delcare: int size=0; and: char sfiles[size][104]; as gobal varibles when i come to compile the code my compiler says "Variable-size type declared outside of any function".

    It works if I put it in a function but i need them to be gobal variables. because lots of funtions use them.

    Can someone please help?
    OS:- XP
    Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>int size=0; and: char sfiles[size][104];
    So, you've actually defined an array with 0 rows?!

    Under c89, dynamic array sizing isn't allowed either, although it's permitted under c99.

    Try using define's:
    Code:
    #define ROW 20
    #define COL 20
    char sfiles[ROW][COL];
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    109
    Is there a way of incresaing the value of #define ROW 20 by 1
    OS:- XP
    Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I presume you mean at runtime? Only by dynamically creating the array in the first place.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Heapsort
    By xENGINEERx in forum C Programming
    Replies: 2
    Last Post: 03-30-2008, 07:17 PM
  2. Pointer Size Relative To Integers?
    By SMurf in forum C Programming
    Replies: 1
    Last Post: 04-18-2006, 06:58 AM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM