this is the code
Code:
#include <stdio.h>#include <string.h>
#define SIZE 10
#define SIZE2 23
typedef struct ItemType {
int Docking_ID;
int Max_size;
int Time_Taken;
float Chargs;
int Ship_ID;
int Ship_Max_Size;
int Actual_Size;
int Arrival_Time;
};
struct ItemType item[SIZE];
int main(){
FILE *file1,*file2; // fisrt file
int i;
char Harbour_Name[6];
int Num_Of_Bays;
int Num_Ship;
file1 = fopen("Port_Data_File.txt", "r"); /* Open first file.txt */
if (file1 == NULL) {
/* Couldn't open the file. */
printf("Input file not found.\n");
return -1; /* Non-zero means error. */
}
/* Introduction */
printf(" ================================================================\n");
printf(" --------------<<<<<<<< WELCOME >>>>>>>>>-----------------------\n");
printf(" ================================================================\n");
printf("+ THIS PROGRAM IS A SIMULATION +\n");
printf("\n");
printf("+ FOR A HARBOUR +\n");
printf("\n");
fscanf(file1,"%d %s",&Num_Of_Bays,Harbour_Name);
printf("\n");
printf("NUMBER OF DOCKING BAYS ARE %d AND THE HARBOUR NAME IS %s\n",Num_Of_Bays,Harbour_Name);
printf("\n");
printf("DOCKING ID MAXIMUN SIZE OF BAY TIME TO UNLOAD CHARGE\n");
printf("========== =================== ============== ======\n");
for (i=0;i<SIZE;i++){
fscanf(file1,"%d %d %d %f",&item[i].Docking_ID,&item[i].Max_size,&item[i].Time_Taken,&item[i].Chargs);
printf("%d\t\t%d\t\t\t%d\t\t%f\n", item[i].Docking_ID,item[i].Max_size,item[i].Time_Taken,item[i].Chargs);
}
file2 = fopen("Boat_Data_File.txt", "r"); /* Open second file.txt */
if (file1 == NULL) {
/* Couldn't open the file. */
printf("Input file not found.\n");
return -1; /* Non-zero means error. */
}
fscanf(file2,"%d",&Num_Ship); // take the input of numbers from the file
printf("\n"); // space of line
printf("NUMBER OF SHIPS ARE %d\n",Num_Ship); // display number of ships
printf("\n"); // space of line
printf("SHIP ID MAXIMUN SIZE OF SHIP ACTUAL SIZE TIME TAKEN\n");
printf("======= =================== =========== ===========\n");
for (i=0;i<SIZE;i++){
fscanf(file2,"%d %d %d %d",&item[i].Ship_ID,&item[i].Ship_Max_Size,&item[i].Actual_Size,&item[i].Arrival_Time);
printf("%d\t\t%d\t\t\t%d\t\t%d\n", item[i].Ship_ID,item[i].Ship_Max_Size,item[i].Actual_Size,item[i].Arrival_Time);
}
for (i=0;item[i].Max_size>=item.Ship_Max_Size;i++){
printf("%d\t\t%d\t\t\t%d\t\t%d\n", item[i].Ship_ID,item[i].Ship_Max_Size,item[i].Actual_Size,item[i].Arrival_Time);
}
getchar();
return 0;
}
waiting the answers guys .. and thank you for helping