complit.c 759 B

123456789101112131415161718192021222324252627282930313233
  1. /* complit.c -- compound literals */
  2. #include <stdio.h>
  3. #define MAXTITL 41
  4. #define MAXAUTL 31
  5. struct book { // structure template: tag is book
  6. char title[MAXTITL];
  7. char author[MAXAUTL];
  8. float value;
  9. };
  10. int main(void)
  11. {
  12. struct book readfirst;
  13. int score;
  14. printf("Enter test score: ");
  15. scanf("%d",&score);
  16. if(score >= 84)
  17. readfirst = (struct book) {"Crime and Punishment",
  18. "Fyodor Dostoyevsky",
  19. 11.25};
  20. else
  21. readfirst = (struct book) {"Mr. Bouncy's Nice Hat",
  22. "Fred Winsome",
  23. 5.99};
  24. printf("Your assigned reading:\n");
  25. printf("%s by %s: $%.2f\n",readfirst.title,
  26. readfirst.author, readfirst.value);
  27. return 0;
  28. }