CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Arrays

  1. #1
    Join Date
    Mar 2005
    Posts
    1

    Arrays

    In C, how can I initialize an array set to include a user-defined parameter?

    For example:

    userPattern = userInputStruct->pattern;
    dataPattern[] = { userPattern };

    Of course, that is not the correct syntax. However, I wanted the contents of userPattern (or the data stored in userInputStruct->pattern), which is inputted by the user at run-time, to populate into the dataPattern array. This is for C programming. I couldn't find a forum for 'C' programming, so thought that perhaps this is where it would fit best.

    Thanks for all your help!!!

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: Arrays

    You are coming to the right place.

    Since C doesn't support creating variable size array on the stack, you have to specify the size in the declaration of the array. To populate the array, you can then specify the index.

    Code:
    MyPattern dataPattern[2];
    dataPattern[0] = userPattern;

  3. #3
    Join Date
    Aug 2000
    Location
    New Jersey
    Posts
    968

    Re: Arrays

    Quote Originally Posted by crkp
    In C, how can I initialize an array set to include a user-defined parameter?

    For example:

    userPattern = userInputStruct->pattern;
    dataPattern[] = { userPattern };

    Of course, that is not the correct syntax. However, I wanted the contents of userPattern (or the data stored in userInputStruct->pattern), which is inputted by the user at run-time, to populate into the dataPattern array. This is for C programming. I couldn't find a forum for 'C' programming, so thought that perhaps this is where it would fit best.

    Thanks for all your help!!!
    What is the type for dataPattern?
    We can give you a better answer if you could tell us what types you're trying to use.
    David Maisonave
    Author of Policy Based Synchronized Smart Pointer
    http://axter.com/smartptr


    Top ten member of C++ Expert Exchange.
    C++ Topic Area

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured