Question: Write a C program to dynamically allocate memory for a structure variable, that is able to: ? store students first name, last name and grade

Write a C program to dynamically allocate memory for a structure variable, that is able to: ? store students first name, last name and grade (numeric) for a certain subject. Once the user is done providing input, print the information back to the console

Here is my code so far, it returns null data, therefore I believe that I am not doing my memory allocation correctly

#include

struct user{

char *firstname, *lastname, *subject;

int *grade;

};

int main(void) {

struct user *data;

data = (struct user*)malloc(sizeof(struct user));

printf("Enter first name: ");

scanf(" %s ", data->firstname);

printf(" %s", data->firstname);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!