Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enter code here
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #define STRING_SIZE 10
- #define LINESIZE 128
- #define SIZE 8
- struct mold_data {
- char mold_type[STRING_SIZE];
- char box_type[STRING_SIZE];
- int box_capacity;
- };
- struct mold_data array[SIZE];
- int main (){
- int nob;
- float quantity;
- float num_of_boxes;
- char mold_inserted[STRING_SIZE];
- FILE *myfile = fopen ("Mold_data_for_all_clients.txt", "r" );
- int i=0;
- int j=0;
- int k=0;
- int l=0;
- char *result[4][3];
- char line[LINESIZE];
- char *value;
- for(i=0; i<=3; i++){
- for(j=0;j<=2;j++){
- result[i][j] = NULL;
- }
- }
- i=0;
- printf("Type mold type");
- scanf("%s",mold_inserted);
- printf("Type ordered quantity");
- scanf("%f",&quantity);
- // loop through each entry in "Mold_data_for_all_clients" file //
- while(fgets(line, sizeof(line), myfile)){
- //load mold name
- value = strtok(line, ", ");
- result[i][0] = strdup(value);
- array[i].mold_type==result[i][0];
- //load box type
- value = strtok(NULL, ", ");
- result[i][1] = strdup(value);
- array[i].box_type==result[i][1];
- // load box capacity
- value = strtok(NULL, ", ");
- result[i][2] = strdup(value);
- array[i].box_capacity==result[i][2];
- if (strcmp(mold_inserted,result[i][0])==0)
- {
- num_of_boxes=quantity/array[i].box_capacity;
- nob=ceil(num_of_boxes);
- printf("n %d " "%s",nob,result[i][1]); }
- break;
- //go to next line
- i++;
- }
- fclose(myfile);
- return 0;
- }
Add Comment
Please, Sign In to add comment