Answered! Write code to declare a structure to contain a name, number of pages, and an ID. Declare a variable of the structure…

Write code to declare a structure to contain a name, number of pages, and an ID. Declare a variable of the structure type at the end of the definition (not in a separate statement). Based the previous question, write code to assign the variable declared to values coming from the console to create one record. Add any needed code or directives. C PROGRAM

Expert Answer

 #include <stdio.h>

#include <string.h>

struct Record {
char name[50];
int pages;
int ID;
} my_record;

int main( ) {

char name[50];
int pages, ID;

printf(“Enter name: “);
scanf(“%s”,name);
printf(“Enter number of pages: “);
scanf(“%d”,&pages);
printf(“Enter ID: “);
scanf(“%d”,&ID);

/* Record details */
strcpy( my_record.name, name);
my_record.pages = pages;
my_record.ID = ID;

// printing details
printf(“nName: %s”,my_record.name);
printf(“nPages: %d”,my_record.pages);
printf(“nID: %d”,my_record.ID);

return 0;
}

Still stressed from student homework?
Get quality assistance from academic writers!