Thread: Malloc/and structs plz help

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    53

    Malloc/and structs plz help

    Hi all,

    I'm making a struct like this


    Code:
    typedef struct{
    
    	double *x;
    	double *y;
    }data;
    Then I declare a variable of type 'data' in main.

    is it alright to allocate memory to x & y (as they are array pointers) I have typed it like this.


    Code:
    	data twoColoumbTable;
    	numRows = 100;
    
    	twoColoumbTable.x = malloc(numRows * sizeof(double));
    	twoColoumbTable.y = malloc(numRows * sizeof (double));
    just wanted confirmation that this is correct thanks
    Or should it be more like this
    Code:
    	twoColoumbTable = malloc(2 * numRows * sizeof(double));
    but then i cant allocate memory to the individual members.
    Am hopeing the way iv done it (first eg) it right.

    appreciate the help guys

  2. #2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 01:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM