Question

Write a function that will initialize a variable of type struct case using the following prototype:...

Write a function that will initialize a variable of type struct case using the following prototype:

void initCase(struct case * newCase, int bottles, char * soda);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <string.h>

struct Case
{
int bottles;
char soda[20];
};

void initCase(struct Case * newCase, int bottles, char * soda);
int main() {
  
struct Case newCase;
initCase(&newCase, 12, "Coca Cola");
  
printf("%d\n",newCase.bottles);
printf("%s",newCase.soda);
  
return 0;
}

void initCase(struct Case * newCase, int bottles, char* soda)
{
newCase ->bottles = bottles;
strcpy(newCase->soda, soda);
}

Output:

12
Coca Cola

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
Write a function that will initialize a variable of type struct case using the following prototype:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board...

    Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board is a 2D array of size 3x3. The function will set an id for each cell of the board starting from 1 and stop at 9. The function prototype is ​void​​ ​​InitializeBoard​​(​​int​​ m, ​​int​​ n , ​​char​​ board[][n]) void​​ ​​InitializeBoard​​(​​int​​ m, ​​int​​ n , ​​char​​ board[][n])​​{ ​​int​​ c =​​1​​; ​ for​​(​​int​​ i =​​0​​; i<m; i++){ ​​ for​​(​​int​​ j=​​0​​; j< n; j++){ board[i][j] = c+​​'0'​​;...

  • I need this in C++ Write a function using the following structure and prototype. struct Stats...

    I need this in C++ Write a function using the following structure and prototype. struct Stats { float avg; //Average value of an integer array float median; //Median value of an integer array int *mode; //array containing the modes int nModes; //number of modes in the array int maxFreq; //max frequency of modes }; Stats *avgMedMode(int *,int); The function takes in an integer array and the size of the array. Then returns a pointer to a structure containing the average,...

  • Write a function with the following prototype struct node* copyList(struct node* 1ist) The struct node is...

    Write a function with the following prototype struct node* copyList(struct node* 1ist) The struct node is the same used in question 18. The function should create a new, separate copy of the linked list pointed to by the list parameter and return a pointer to the head of the newly created linked list copy.

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • need help on this! Just write the function prototype for the following finctions while also using...

    need help on this! Just write the function prototype for the following finctions while also using the variables below to help write the prototype! thanks!! WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in main(). I 1.) showMenu 2.) getChoice 3.) calcResult 4.) showResult 5.) getlato 6.) showName 7.) calcSquare 8.) is Positive int main() USE THESE VARIABLES, when needed, to function...

  • C program help 4. Write a function called scan_hex. Here is its prototype: void scan_hex(int *xptr);...

    C program help 4. Write a function called scan_hex. Here is its prototype: void scan_hex(int *xptr); Here is an example of its use, in conjunction with print_decimal. Assume that the user will type a non-negative hex number as input. Also, assume that the “digits” a-f are in lower case. Let’s say the user types 1b int x; scan_hex(&x); print_decimal(x); MODIFY THIS CODE // function inputs a non-negative integer and stores it into *xptr. // The format of the input is...

  • using C: Write code for a function with the following prototype: /* * Mask with least...

    using C: Write code for a function with the following prototype: /* * Mask with least signficant n bits set to 1 * Examples: n = 6 --> 0x3F, n = 17 --> 0x1FFFF * Assume 1 <= n <= w */ int lower_one_mask(int n); Your function should follow the bit-level integer coding rules. Be careful of the case n =w.

  • Answer it by using c++ context. struct courseType struct studentType { { struct name Type {...

    Answer it by using c++ context. struct courseType struct studentType { { struct name Type { string first; string last; }; string name; int callNum; int credits; char grade; name Type name; double gpa; courseType course; }; student Type student; student Type classList[100]; course Type course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. a. student.name.last="Anderson"; b. classList[1].name = student; c. student.name = classList[10].name;

  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • Write a prototype for the following function: void printNum(int number) {     cout << “The number...

    Write a prototype for the following function: void printNum(int number) {     cout << “The number is: “ << number << endl; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT