Using malloc() to declare structs

I am trying to create a linked list using malloc() for a program in C. I have a sentence and I need to put each word into a struct and give it a sequence number. So for example if the sentence is "Sample sentence" then I would have 'S' with sequence number '1' in struct #1 and 'a' with sequence number 2 in struct #2. Total sequence is then the opposite and in this case 'S' would hold 15 and 'a' would hold 14 and so on.. This is my code..

int main( void ){

char array[100];
int size= strlen(array);
int i;

struct node {
char c;
int sequence;
int totalSequence;
struct node *next;

struct node *head= malloc(sizeof(struct node)*size);

struct node [i].c= array[0]; //i know this does not work but i dont know why

can somebody suggest a correct method of assigning each letter to each struct? I can then figure out the number sequence from that on my own. Thanks a lot!
Last edited on
Topic archived. No new replies allowed.