i'm trying to apply malloc in my code, but still having a problem, there's an error saying : "request for member 'id' in something not a structure or union".
what i want to do is to use malloc instead of array.. and store the structure in each indices, i tried array[i]->id, but bunch of garbage character stored on my text file. I also increment i and didn't use loop, coz user may only input once... this is my code:
#include<stdio.h>
#include<stdlib.h>
struct studentinfo{
       char id[8];
       char name[30];
       char course[5];
}s1;
main(){
    int i=0;
    FILE *stream = NULL;
    stream = fopen("studentinfo.txt", "a+");    
    struct studentinfo *array[50];
    array[i] = (struct studentinfo*) malloc(sizeof(struct studentinfo));
       printf("Enter Student ID: ");
       scanf("%s", array[i].id);
       fflush(stdin);
       printf("Enter Student Name: ");
       gets(array[i].name);
       fflush(stdin);
       printf("Enter Student Course: ");
       scanf("%s", array[i].course);
       fprintf(stream, "\n%s,\t%s,\t%s", array[i].id, array[i].name, array[i].course);
       i++;
       fclose(stream);
       free(array);
    getch();
}
hope you can help me... thanks in advance :)
 
     
     
     
    