Answer to Question #317964 in C for Tiu

Question #317964

 Man's Best Friend

by CodeChum Admin

We all know what man's best friend is. A dog! 🐶


Let's create one in our program using the pre-existing struct Dog provided.



Instructions:

  1. In the code editor, you are provided with the definition of a struct Dog. This struct needs a string value for its breed. Furthermore, you are provided with a displayDog() function which accepts a struct Dog as its parameter.
  2. Your task is to create a Dog, take in a string user input, and then set it as the Dog's breed.
  3. Finally, call the displayDog() function and pass that Dog you created.
1
Expert's answer
2022-03-26T02:38:48-0400
#include <stdio.h>

struct Dog {
    char breed[40];
};

void displayDog(struct Dog dog)
{
    printf("\nDog breed: %s\n", dog.breed);
}

int main()
{
    struct Dog dog;
    
    printf("Input string: ");
    scanf("%s", dog.breed);
    displayDog(dog);
    getchar();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS