User Profile

Collapse

Profile Sidebar

Collapse
apmsbask
apmsbask
Last Activity: Oct 26 '10, 09:15 AM
Joined: May 21 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Dear Banfa

    Thanks for your reply. Your suggestion works well.

    I also found an alternate way to do it. In fact somewhere in the web, I read that when declaring a struct, one has to know the array size apriori. But this is not true. For instance, the following program works
    Code:
    //---------------------------------------------------------------------------------------
    #include <stdio.h>
    #include <stdlib.h>
    ...
    See more | Go to post
    Last edited by Niheel; May 22 '10, 03:36 AM. Reason: codetags

    Leave a comment:


  • apmsbask
    started a topic Multi-Dimensional variable in struct in C program
    in C

    Multi-Dimensional variable in struct in C program

    I am stuck with how to access a 2-d array declared in a structure. For instance, I have declared a struct as follows:

    Code:
    struct sv {
    float a[10][10];
    };
    Now in main function, how to access the variable 'a'? I tried the following

    Code:
    main () {
    struct sv * p;
    p = (struct sv *) malloc (sizeof(struct sv));
    *(p->*(a+1)+1) = 20.0;
    printf("%f\n",*(p->*(a+1)+1));
    ...
    See more | Go to post
    Last edited by Niheel; May 22 '10, 03:36 AM. Reason: codetags
No activity results to display
Show More
Working...