Write all the C statements needed to define a new programmer defined type that c
ID: 3801501 • Letter: W
Question
Write all the C statements needed to define a new programmer defined type that contains a character string of up to 15 characters (including the ''), two integers, a float, and a pointer to another instance of that type. b. Now write the C statements needed to declare a variable of the type from part a, assign the value 100.0 to the float member of that variable and assign the string "44 rocks!" to the character string member of that variable. c. Now write the C statements needed to dynamically allocate an instance of the type you defined in part a, and then copy all the members of the variable declared in part b to that dynamically allocated instance.Explanation / Answer
/* I have written your requirement as program which includes all the three parts*/
a)struct new programmer
{
char[15] name;
int a;
int b;
float x;
} ;
void read_part(struct new programmer *partptr);
void print_part(struct new programmer *partptr);
main()
{
struct new programmer value;
read_part(&value);
print_part(&value);
}
c) /*Printing all values with dinamically allocated values*/
void print_part(struct new programmer *partptr)
{
printf("a=%d, b=%d, x=%4.2f, name=%ch);
}
b) /*assigning values as per part b*/
void read_part(struct new programmer *partptr)
{
value.x=100.00;
value.name="coen 44 rocks";
int c;
int d;
printf("a is equal to");
scanf("%d",&c);
(*partptr).a=c;
printf("b is equal to");
scanf("%d",&d);
(*partptr).b=d;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.