Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C, write a simple program to define a struct template and define it as a datatype using typedef. Than allocate a block of dynamically

In C, write a simple program to define a struct template and define it as a datatype using typedef. Than allocate a block of dynamically allocated memory and set the values for the different members. Than have them print out the contents.

When running the code below I get these 2 errors. Any help is appreciated

1. return type of main is not int

2. must use struct tag to refer to type patient

#include

#include //for malloc

#include

struct patient

{ char name[20]; int age; float weight; float height; int pulse_rate; };

void main()

{

typedef patient Patient; //typedef definition used now we have new variable type Patient

Patient *P; // Patient type pointer variable declared

P=(Patient*)malloc(50*sizeof(Patient)); //dynamically allocating memory by malloc

if(P==NULL)

{ printf("couldn't allocate memory ");

}

else

{

strcpy(P->name,"Daniel"); //directly asigning values to the members

P->age=34;

P->weight=180.0;

P->height=70.3;

P->pulse_rate=60;

}

printf("Details are: ");

printf("name:%s ",P->name);

printf("age:%d ",P->age);

printf("pulse_rate:%d ",P->pulse_rate);

printf("height:%f ",P->height);

printf("weight:%f ",P->weight);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

=+ Are there additional forms of employee representation?

Answered: 1 week ago

Question

=+What is the nature of their impact?

Answered: 1 week ago