fork download
  1. #include <stdio.h>
  2.  
  3. struct Garden
  4. {
  5. int num_animals;
  6. int size;
  7. char type[10];
  8. };
  9.  
  10. void Input(struct Garden *gardname)
  11. {
  12. printf("\nEnter number of animals\n");
  13. scanf("%d", &(gardname->num_animals));
  14.  
  15. /*you could also write gardname->num_animals, as mentioned in the comment*/
  16.  
  17. printf("\nEnter size\n");
  18. scanf("%d",&(gardname->size));
  19.  
  20. printf("\nEnter type\n");
  21. scanf("%s", gardname->type);
  22. }
  23.  
  24.  
  25. void Output(struct Garden *gardname)
  26. {
  27. printf("Num of animals:%d\n",gardname->num_animals);
  28. printf("size:%d\n",gardname->size);
  29. printf("type:%s\n",gardname->type);
  30. }
  31.  
  32. int main()
  33. {
  34. struct Garden Lumbini = { .size = 1, .type = "asdf", .num_animals = 5 };
  35. Input(&Lumbini);
  36. Output(&Lumbini);
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 2172KB
stdin
2
3
asdffffasdf
stdout
Enter number of animals

Enter size

Enter type
Num of animals:2
size:3
type:asdffffasdf