Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6. #define PAUSE system("pause")
  7. #define CLS system("cls")
  8. #define FLUSH fflush(stdin)
  9.  
  10.  
  11. typedef struct
  12. {
  13. char name[40];
  14. int customerID;
  15. double amountOwning;
  16. }CUSTOMER;
  17.  
  18. CUSTOMER* makeACustomer()
  19. {
  20. CUSTOMER* result;
  21. result = malloc(sizeof(CUSTOMER));
  22.  
  23. return result;
  24.  
  25. }// end of didn't even prototype the factoryFunction();
  26.  
  27. void getCustomerInfo(CUSTOMER* customer){
  28. printf("Enter the Customer's name:");
  29. scanf("%s", customer->name);
  30. printf("Enter the Customer's ID:");
  31. scanf("%i", customer->customerID);
  32. printf("Enter the Amount owed:");
  33. scanf("%lf", customer->amountOwning);
  34. }// end of getcustomerinfo()
  35.  
  36. main()
  37. {
  38. int i;
  39. CUSTOMER myCustomers[10];
  40. CUSTOMER *myDynamicCustomers;
  41.  
  42. CUSTOMER* *myIndividualCustomers;
  43. CUSTOMER firsCustomer;
  44.  
  45. getCustomerInfo(&firsCustomer);
  46.  
  47. myIndividualCustomers = calloc(10, sizeof(CUSTOMER*));
  48. for (i = 0; i < 10; i++)
  49. {
  50. myIndividualCustomers[i] = makeACustomer();
  51.  
  52. }// end of for loop.
  53.  
  54. myDynamicCustomers = calloc(10, sizeof(CUSTOMER));
  55.  
  56. if (myCustomers == NULL)
  57. {
  58. printf("Error allocating memory...");
  59. exit(-1);
  60. }// end of if statement
  61.  
  62. strcpy(myIndividualCustomers[0]->name, "Judy XXXXX");
  63. myIndividualCustomers[0]->amountOwning = 789.99;
  64. myIndividualCustomers[0]->customerID = 789456;
  65.  
  66.  
  67.  
  68.  
  69. strcpy(myCustomers[0].name, "Bob Smith");
  70. myCustomers[0].customerID = 12345;
  71. myCustomers[0].amountOwning = 123.45 ;
  72.  
  73. strcpy(myCustomers[1].name, "Mary Jones");
  74. myCustomers[1].customerID = 54321;
  75. myCustomers[1].amountOwning = 456.78;
  76.  
  77. strcpy(myCustomers[2].name, "Judy XXXXXX");
  78. myCustomers[2].customerID = 1017;
  79. myCustomers[2].amountOwning = 6767.21;
  80.  
  81.  
  82. free(myDynamicCustomers);
  83.  
  84.  
  85.  
  86.  
  87. PAUSE;
  88.  
  89. }// end of main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement