Data Structure with array in it

This is a discussion on Data Structure with array in it within the C Programming forums, part of the General Programming Boards category; Code: typedef struct data{ int courseSize; int adjMat[courseSize][courseSize]; course arrCourse[courseSize]; struct data *next; }set; How can I get rid of ...

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    10

    Data Structure with array in it

    Code:
    typedef struct data{
        int courseSize;
        int adjMat[courseSize][courseSize];
        course arrCourse[courseSize];
        struct data *next;
    }set;
    How can I get rid of this? It tells that in int adjMat[courseSize][courseSize]; and course arrCourse[courseSize]; courseSize in undeclared. Help please!

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    148
    Quote Originally Posted by deoxys0100 View Post
    [code]

    courseSize in undeclared.
    your compiler seems to be right..

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2,915
    In C arrays usually need to have compile time constants for their sizes so courseSize should be #defined outside the class with the proper value.

    Jim

  4. #4
    Registered User
    Join Date
    Jan 2014
    Posts
    10
    Quote Originally Posted by jimblumberg View Post
    In C arrays usually need to have compile time constants for their sizes so courseSize should be #defined outside the class with the proper value.

    Jim
    I actually have something like this:

    Code:
    scanf("%d", &num);
    set *node = (set *)malloc(sizeof(set));
    node->courseSize = num;
    How can I change the value of courseSize inside my arrays without declaring a definite value?

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by deoxys0100 View Post

    How can I change the value of courseSize inside my arrays without declaring a definite value?
    You can't. You probably need to change the type (to int** and int*) and then do some more malloc'ing once you've determined the value of courseSize.

  6. #6
    Registered User
    Join Date
    Jan 2014
    Posts
    10
    Quote Originally Posted by tabstop View Post
    You can't. You probably need to change the type (to int** and int*) and then do some more malloc'ing once you've determined the value of courseSize.
    Thank you so much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with implementing trie data structure with dynamic array
    By x-lichking2013 in forum C Programming
    Replies: 8
    Last Post: 06-28-2013, 09:30 PM
  2. How to store data structure into 2D array?
    By gevni in forum C Programming
    Replies: 2
    Last Post: 03-22-2013, 04:18 PM
  3. Replies: 5
    Last Post: 09-17-2011, 09:53 PM
  4. Replies: 1
    Last Post: 04-14-2011, 12:15 PM
  5. Replies: 2
    Last Post: 03-05-2005, 04:00 PM

Tags for this Thread


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