Write the code that defines a struct called tune. The following information must
ID: 3571678 • Letter: W
Question
Write the code that defines a struct called tune. The following information must be kept in appropriate data types: the artist of the tune (assume there are no white spaces in the artist name) the name of the tune (assume there are no white spaces in the name) the length of the tune (use an integer for number of seconds) the cost of the tune the year of the tune Write a function called GetTunelnfo that takes a pointer to a tune structure, as its only argument. The function prompts the user for the required information to fill the structure and stores it in the appropriate fieldsExplanation / Answer
/* header files */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* structure tune */
struct tune {
/* information of tunes stored in an appropriate data type */
char artist_name[100];
char name_tune[100];
int length_tune;
int cost_tune;
int year_tune;
};
/* function to store structure fields with user input */
void getTuneInfo(struct tune* tune_ptr){
/* prompting user to enter information of tune and storing them in the appropriate fields */
printf("Enter name of the artist : ");
scanf("%s",tune_ptr->artist_name);
printf("Enter name of the tune :");
scanf("%s",tune_ptr->name_tune);
printf("Enter length of the tune : ");
scanf("%d",&tune_ptr->length_tune);
printf("Enter cost of the tune : ");
scanf("%d",&tune_ptr->cost_tune);
printf("Enter year of the tune : ");
scanf("%d",&tune_ptr->year_tune);
/* printing the value of stored fields */
printf("%s ",tune_ptr->artist_name);
printf("%s ",tune_ptr->name_tune);
printf("%d ",tune_ptr->length_tune);
printf("%d ",tune_ptr->cost_tune);
printf("%d ",tune_ptr->year_tune);
}
int main()
{ /* initializing pointer variable of type struct tune */
struct tune* tune_ptr=malloc(sizeof(struct tune));
/* calling method getTuneInfo and passing structure pointer as a variable */
getTuneInfo(tune_ptr);
return 0;
}
/*********OUTPUT*********
Enter name of the artist : david
Enter name of the tune :trans
Enter length of the tune : 50
Enter cost of the tune : 400
Enter year of the tune : 2012
david
trans
50
400
2012
**********OUTPUT**********/
/* Note: This code has been done in c and tested on gcc compiler,Please do ask in case of any doubt,
would glad to help,Thanks !! */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.