Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, i am working on a C language program to read flowshop data files. These file

ID: 3882849 • Letter: H

Question

Hi, i am working on a C language program to read flowshop data files.

These files contain two-dimensional information where the rows are the tasks and columns are the machines.

The following examples are two data files.

20 5

0 5 1 76 2 74 3 99 4 26

0 74 1 21 2 83 3 52 4 90

0 67 1 48 2 6 3 66 4 38

0 97 1 36 2 71 3 68 4 81

0 87 1 86 2 64 3 11 4 31

0 1 1 42 2 20 3 90 4 23

0 69 1 32 2 99 3 26 4 57

0 69 1 12 2 54 3 80 4 16

0 11 1 63 2 24 3 16 4 89

0 87 1 52 2 43 3 10 4 26

0 25 1 59 2 88 3 87 4 40

0 50 1 42 2 72 3 77 4 29

0 58 1 76 2 71 3 82 4 94

0 79 1 48 2 20 3 63 4 97

0 35 1 57 2 78 3 99 4 80

0 70 1 76 2 53 3 2 4 19

0 79 1 22 2 77 3 74 4 95

0 34 1 99 2 49 3 3 4 61

0 37 1 24 2 32 3 35 4 4

0 50 1 88 2 46 3 63 4 76

____________________________________________________________

20 15

0 78 1 37 2 79 3 98 4 100 5 21 6 82 7 27 8 7 9 22 10 9 11 57 12 84 13 91 14 5

0 13 1 81 2 100 3 77 4 45 5 39 6 60 7 87 8 38 9 91 10 17 11 85 12 43 13 81 14 33

0 47 1 9 2 31 3 40 4 86 5 27 6 69 7 50 8 87 9 34 10 13 11 15 12 95 13 96 14 72

0 26 1 61 2 5 3 22 4 26 5 52 6 57 7 97 8 10 9 68 10 8 11 49 12 41 13 16 14 35

0 68 1 41 2 46 3 58 4 37 5 59 6 22 7 43 8 49 9 21 10 42 11 70 12 13 13 2 14 76

0 47 1 60 2 23 3 23 4 57 5 60 6 35 7 56 8 54 9 73 10 81 11 61 12 15 13 70 14 51

0 63 1 21 2 10 3 50 4 12 5 84 6 91 7 7 8 44 9 75 10 60 11 72 12 28 13 83 14 52

0 52 1 100 2 38 3 79 4 90 5 52 6 81 7 54 8 51 9 11 10 76 11 50 12 24 13 12 14 23

0 91 1 21 2 59 3 55 4 39 5 75 6 3 7 11 8 14 9 24 10 36 11 72 12 48 13 69 14 55

0 100 1 54 2 77 3 53 4 90 5 91 6 53 7 68 8 18 9 86 10 28 11 61 12 86 13 36 14 15

0 63 1 58 2 93 3 24 4 18 5 78 6 74 7 57 8 100 9 92 10 51 11 73 12 6 13 12 14 83

0 96 1 60 2 79 3 84 4 86 5 31 6 41 7 79 8 63 9 17 10 31 11 65 12 41 13 77 14 74

0 54 1 55 2 89 3 77 4 40 5 71 6 21 7 43 8 60 9 58 10 13 11 3 12 73 13 44 14 85

0 50 1 33 2 51 3 100 4 46 5 27 6 30 7 80 8 56 9 50 10 97 11 70 12 9 13 22 14 92

___________________________________________________________________________________

The first line indicates the number of tasks and machines. The rest is the data where each row represents a task combined with (machine-id, job-size) pairs.

So the C program needs to:

-Read the data file

-Create a 2-d array according to the number of tasks and machines

-read the data and store them to the array

-print out the array

for the first test file the printout should look like:

5 74 67 97 87 1 69 69 11 87 25 50 58 79 35 70 79 34 37 50

76 21 48 36 86 42 32 12 63 52 59 42 76 48 57 76 22 99 24 88

74 83 6 71 64 20 99 54 24 43 88 72 71 20 78 53 77 49 32 46

99 52 66 68 11 90 26 80 16 10 87 77 82 63 99 2 74 3 35 63

26 90 38 81 31 23 57 16 89 26 40 29 94 97 80 19 95 61 4 76

________________________________________________

Thank you for the help.

Explanation / Answer

#include<stdlib.h>
#include<stdio.h>

int main()
{
FILE *fp;
int m,n,i,j;
int **arr;
int dim[2];

char file_name[20];
//reading file name from user
printf("Enter file Name :");
scanf("%s", file_name);

fp = fopen(file_name, "r"); //opening file in read mode

if(fp == NULL) //if file is not present in working dir
{
printf(" Cannot open file ");
exit(0);
}
//reading dimension of matrix
for(i = 0; i < 2; i++)
{
if(!fscanf(fp, "%d", &dim[i]))
break;
}
m = dim[0];
n = 2 * dim[1]; //for column as column is 2 * given value

arr = (int **)malloc(m * sizeof(int *)); //creating 2-D array for reading data from file

for (i=0; i < m; i++)
arr[i] = (int *)malloc(n * sizeof(int));

//reading all data except first line in 2-D array
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
if(!fscanf(fp, "%d ", &arr[i][j]))
break;
}
}
//printing array by alternate column wise
for(i = 1; i < n; i += 2)
{
for(j = 0; j < m; j++)
{
printf("%d ", arr[j][i]);
}
printf(" ");
}
for (i = 0; i < m; i++)
{
free(arr[i]);
}
free(arr);
fclose(fp); //closing file.

return 0;
}

Please refer below snapshot for reference.

I have copied data in Machine.txt

Enter file Name :Machine.txt
5 74 67 97 87 1 69 69 11 87 25 50 58 79 35 70 79 34 37 50
76 21 48 36 86 42 32 12 63 52 59 42 76 48 57 76 22 99 24 88
74 83 6 71 64 20 99 54 24 43 88 72 71 20 78 53 77 49 32 46
99 52 66 68 11 90 26 80 16 10 87 77 82 63 99 2 74 3 35 63
26 90 38 81 31 23 57 16 89 26 40 29 94 97 80 19 95 61 4 76

Process returned 0 (0x0) execution time : 4.536 s
Press any key to continue.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote