Applying malloc

guys... can u help me apply malloc in my code... here's my code:

#include<stdio.h>
#include<stdlib.h>
struct studentinfo{
       char id[8];
       char name[30];
       char course[5];
}s1;
main(){
    int i;
    FILE *stream = NULL;
    stream = fopen("studentinfo.txt", "a+");

    struct studentinfo s1;
    struct studentinfo array[3];
    for (i =0; i<1; i++){
       printf("Enter Student ID: ");
       scanf("%s", s1.id);
       fflush(stdin);
       printf("Enter Student Name: ");
       gets(s1.name);
       fflush(stdin);
       printf("Enter Student Course: ");
       scanf("%s", s1.course);

       fprintf(stream, "\n%s,\t%s,\t%s", s1.id, s1.name, s1.course);
    }
       fclose(stream);
    getch();
}

i know malloc alots more space than the usual array... but still im having a hard time using it... thanks a lot :)

Answers


Before we help you, be sure to do this:

Then:

  • Tell us what you want to achieve;
  • Tell us what's actually happening;
  • Tell us what you've tried;
  • Tell us what's bothering you;
  • Tell us what you don't understand.

Compiler and program outputs help as well.

PS: Sort of expecting a down-vote, but that needed to be done.


Need Your Help

Different ways to enumerate a collection

c# collections c#-4.0

From the below 2 ways to enumerate a collection, should one be preferred over the other OR are both the same in terms of performance (i.e. since ToList() conversion is involved in the second approa...

VB.NET - Inherits System.Web.UI.WebControls.DropDownList doesn't call “Render” method

asp.net vb.net inheritance drop-down-menu

I have the following code, and when I put a Control of this type on a WebForm, it does not throw the Exception as you would expect it to, instead a &lt;SELECT&gt; is nicely rendered.