Structures...

Joined
May 9, 2012
Messages
2
Reaction score
0
Greetings from Greece!, Nice to meet you~

Well, I have to write a C script, and while i do have the whole algorithm in mind, I must save certain data as an array of struct at the beginning of the script. I have never used Structs, so i looked them up on the web, and got a handle about them, but I can't seem to fill an array right...


this is my code.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
typedef unsigned int id_t;
typedef unsigned int num_t;
typedef struct mystr
{ 
    id_t id;
    num_t num;
}

mystr;


int main()
{    
    int i;
    mystr st[10]={ 
    
    [1]={
        .id = 0,
        .num = 0
         },

    [2]={
        .id = 0,
        .num = 0
         }
    
    };
    
}


I intend to Loop it in a for, and have the array filled as = { }; but... i dont know if that would work

The errors i get are:
request for member 'id' in something not a struct or union
request for member 'num' in something not a struct or union.

Its 10:15pm here, and I have to attend class at 9am~

Any help would be appreciated, thanks beforehand!
 
Joined
May 9, 2012
Messages
2
Reaction score
0
nevermind, i just solved it, after playing around with it for a while xP.

sorry for the annoyance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top