fork(1) download
  1. #include <stdio.h>
  2.  
  3. /* Supporting structures */
  4. struct date { int month; int date; int year; };
  5.  
  6. struct producer {
  7. char name[100];
  8. char city[50];
  9. char state[50];
  10. char country[50];
  11. };
  12.  
  13. struct volume {
  14. float amount;
  15. char unit[10];
  16. };
  17.  
  18. struct priceInfo {
  19. float price;
  20. char currency[10];
  21. };
  22.  
  23. /* Base structures */
  24. struct Beer {
  25. int stockID;
  26. struct date bornOnDate;
  27. char type[70];
  28. char brand[100];
  29. float abv;
  30. struct producer brewery;
  31. struct volume container;
  32. struct priceInfo pricing;
  33. int ibu;
  34. int calories;
  35. int stockQuantity;
  36. int shelfLifeMonths;
  37. int isCraft;
  38. };
  39.  
  40. struct Wine {
  41. int stockID;
  42. char varietal[70];
  43. char brand[100];
  44. int vintage;
  45. float abv;
  46. char region[70];
  47. struct producer winery;
  48. struct volume container;
  49. struct priceInfo pricing;
  50. char sweetness[20];
  51. int agingMonths;
  52. int stockQuantity;
  53. int isSparkling;
  54. };
  55.  
  56. struct Spirits {
  57. int stockID;
  58. char type[50];
  59. char brand[100];
  60. int age;
  61. float abv;
  62. struct producer distillery;
  63. struct volume container;
  64. struct priceInfo pricing;
  65. char barrelType[50];
  66. int proof;
  67. int stockQuantity;
  68. int isImported;
  69. };
  70.  
  71. /* Test main function */
  72. int main(void) {
  73. struct Beer myBeer = {
  74. 1001, {8, 10, 2025}, "IPA", "Sample Brew", 6.5,
  75. {"Sample Brewery", "City", "State", "Country"},
  76. {12.0, "oz"}, {5.99, "USD"}, 45, 180, 50, 6, 1
  77. };
  78.  
  79. printf("Beer: %s (%s), ABV: %.1f%%, Price: %.2f %s\n",
  80. myBeer.brand, myBeer.type, myBeer.abv,
  81. myBeer.pricing.price, myBeer.pricing.currency);
  82.  
  83. return 0;
  84. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Beer: Sample Brew (IPA), ABV: 6.5%, Price: 5.99 USD