Guest User

Untitled

a guest
Mar 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. enter code here
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <math.h>
  7.  
  8. #define STRING_SIZE 10
  9. #define LINESIZE 128
  10. #define SIZE 8
  11.  
  12. struct mold_data {
  13.  
  14. char mold_type[STRING_SIZE];
  15. char box_type[STRING_SIZE];
  16. int box_capacity;
  17. };
  18.  
  19. struct mold_data array[SIZE];
  20.  
  21. int main (){
  22.  
  23. int nob;
  24. float quantity;
  25. float num_of_boxes;
  26. char mold_inserted[STRING_SIZE];
  27.  
  28. FILE *myfile = fopen ("Mold_data_for_all_clients.txt", "r" );
  29. int i=0;
  30. int j=0;
  31. int k=0;
  32. int l=0;
  33. char *result[4][3];
  34. char line[LINESIZE];
  35. char *value;
  36.  
  37. for(i=0; i<=3; i++){
  38. for(j=0;j<=2;j++){
  39. result[i][j] = NULL;
  40. }
  41. }
  42. i=0;
  43.  
  44. printf("Type mold type");
  45. scanf("%s",mold_inserted);
  46. printf("Type ordered quantity");
  47. scanf("%f",&quantity);
  48.  
  49. // loop through each entry in "Mold_data_for_all_clients" file //
  50.  
  51. while(fgets(line, sizeof(line), myfile)){
  52.  
  53. //load mold name
  54. value = strtok(line, ", ");
  55. result[i][0] = strdup(value);
  56. array[i].mold_type==result[i][0];
  57.  
  58. //load box type
  59. value = strtok(NULL, ", ");
  60. result[i][1] = strdup(value);
  61. array[i].box_type==result[i][1];
  62.  
  63.  
  64. // load box capacity
  65. value = strtok(NULL, ", ");
  66. result[i][2] = strdup(value);
  67. array[i].box_capacity==result[i][2];
  68.  
  69.  
  70. if (strcmp(mold_inserted,result[i][0])==0)
  71.  
  72. {
  73. num_of_boxes=quantity/array[i].box_capacity;
  74. nob=ceil(num_of_boxes);
  75.  
  76. printf("n %d " "%s",nob,result[i][1]); }
  77. break;
  78.  
  79. //go to next line
  80. i++;
  81. }
  82.  
  83.  
  84. fclose(myfile);
  85. return 0;
  86. }
Add Comment
Please, Sign In to add comment