Thread: Scanning for a variable that will be the size of an array.

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    Scanning for a variable that will be the size of an array.

    Code:
    int rows, cols;
    scanf("%d %d\n", &rows, &cols);
    char drawing[rows][cols];
    I am getting a mixed declaration with code error. How can I do this? (I have to compile this program with specific settings so compiling it differently is not an option.)

    Any help is appreciated.
    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If "no compiling it differently" means "must be C89" you are so screwed. In that case, you will have to use malloc and co to get a chunk of memory and manage it yourself (buzzword: DYNAMIC).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM