+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Newbie level 4
    Points: 48, Level: 1

    Join Date
    Apr 2013
    Posts
    6
    Helped
    0 / 0
    Points
    48
    Level
    1

    How to read a values from the structure in C

    #include
    #define msize 4096

    struct memory
    {
    int a[msize];
    };

    void main()
    {
    struct memory m;
    m.a[0]=250; // temperature value of 25,0
    m.a[4]=01; // heater status OFF
    m.a[8]=240; // temperature value of 24,0
    m.a[12]=00; // heater status ON
    m.a[16]=220; // temperature value of 22,0
    m.a[20]=00; // heater status ON
    read(&m);

    }

    void read(struct memory m)
    {
    int i;
    for(i=0;i {
    scanf("%d", m.a[i]);
    }
    }


    the code is showing error in void read function as first defined here .

    Please some one also help me to convert this read value to ASCII ??

    •   AltAdvertisement

        
       

  2. #2
    Full Member level 6
    Points: 2,985, Level: 12
    Achievements:
    7 years registered

    Join Date
    Apr 2011
    Posts
    337
    Helped
    23 / 23
    Points
    2,985
    Level
    12

    Re: How to read a values from the structure in C

    the code is showing error in void read function as first defined here .
    you have to declare function prototype at the top of the code [functions should be declared before using it]. So, place the function void read(struct memory m) before main function where you called this function from main.

    #define msize 4096
    Which PIC you are using? do you have such amount of data memory in your PIC MCU (4 KB).

    suggestion: google struct in C



    •   AltAdvertisement

        
       

  3. #3
    Newbie level 5
    Points: 1,508, Level: 8
    Achievements:
    7 years registered

    Join Date
    Jan 2008
    Posts
    9
    Helped
    0 / 0
    Points
    1,508
    Level
    8

    Re: How to read a values from the structure in C

    you might solve the errors like following:

    #include
    #define msize 4096

    struct memory
    {
    int a[msize];
    };

    void read(struct memory m)
    {
    int i;
    for(i=0;i {
    scanf("%d", &m.a[i]);
    }
    }


    int main()
    {
    struct memory m;
    m.a[0]=250; // temperature value of 25,0
    m.a[4]=01; // heater status OFF
    m.a[8]=240; // temperature value of 24,0
    m.a[12]=00; // heater status ON
    m.a[16]=220; // temperature value of 22,0
    m.a[20]=00; // heater status ON
    read(m);

    }



--[[ ]]--