Neil Devlin wrote:

I don't understand what you're trying to do. Your code is broken - could you
give us a more complete example?

Sorry to pick at your code sample, but one of these might be your problem!

> typedef struct{
>  int one[10];
>  int dummy;
> }Test

You'll need a semi-colon after Test here.

> Test arr[10];
>  
> for(int loop=1;loop<11;loop++)
>   arr.one[loop]=loop;

Several problems here:

  - arr is an empty array of ten pointers to Test structures; you
    haven't initialised any of them.

  - arr.one doesn't make sense; arr isn't of Test type, it's a Test*;
    you'd need to new a Test and then use arr[0]->one or similar, or
    did you mean "Test arr;" not "Test arr[10];"?

  - one[10] is initialised for 0-9, not 1-10. In your case you'll
    probably end up writing dummy as one[10] but I don't think you
    should rely on that. And you won't see one[0]==1 as you comment.

For what it's worth, this works fine for me:

    #include <stdio.h>

    typedef struct
    {
        int one[10];
        int dummy;
    } Test;

    Test arr;

    void afunction(Test *ptr)
    {
        printf("%d\n",ptr->one[0]);
    }

    int main(void)
    {
        for(int loop=0; loop < 10; ++loop)
            arr.one[loop]=loop;

        afunction(&arr);
        return 0;
    }

Rup.


_______________________________________________
msvc mailing list
msvc@beginthread.com
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for 
subscription changes, and list archive.

Reply via email to