c – Reading txt file

it is necessary to do the reading of files with some parameters, the algorithm is a stepper of processes, I need to enter with the n of processes, waiting time, Quantum … I am not knowing where to start the reading.

include

struct processM {
int name;
inturst;
intazeTime;
int burstTotal;
int type Escalation;
};

struct processM process[20];

struct processRR {
int name;
inturst;
intazeTime;
int burstTotal;
};

struct processRR processRR[20];

struct processSRTF {
int name;
inturst;
intazeTime;
int burstTotal;
int arrival;
};

struct processSRTF processSRTF[20];

void fcfs ();
void sjf ();
void srtf ();
void roundrobin ();
multilevel void ();

int verifySRTFEntry (int, int);
void executeProcessoSRTF (int, int, int);
void verifyWaitingTimeSRTF (int, int, int);
int selects NovoProcessoSRTF (int);
int verifies FimSRTF (int);

void executingRRProcess (int, int);
void accountWaitingTimeRR (int, int);

void executionRRMProcess (int, int);
void executeProcess JSFM (int);
void accountWaitingTimeRRM (int, int);

int main (void)
{
int value;

printf ("Type a stagger: n n");
printf ("1) FCFS n");
printf ("2) SJF n");
printf ("3) SRTF n");
printf ("4) ROUND ROBIN n");
printf ("5) MULTILEVEL n");
printf ("6) EXIT n n");
scanf ("% d", & value);

switch (value)
{
case 1:
FCFS ();
to break;

    case 2:
SJF () ;;
to break;

case 3:
SRTF () ;;
to break;

case 4:
RoundRobin ();
to break;

case 5:
multilevel ();
to break;

case 6:
printf (" nFim.  n");
to break;

Default:
printf ("Invalid value!  n");

}

return 0;
}

// ********************************************** ********************************************** ******
// ********************************************** ********************************************** ******
// SCALING FCFS
// ********************************************** ********************************************** *****
// ********************************************** ********************************************** ******

void fcfs () {f}
int n, bt[20]WT[20]tat[20], AVwt = 0, avtat = 0, i, j;
printf ("Enter total number od processes (maximum 20):"); // Process number entry
scanf ("% d", & n);
printf (" nEnter Process Burst Time n");

(i = 0; i <n; i ++) {// Fill the process burst
printf ("P[%d]: ", i + 1);
scanf ("% d", and bt[i]); // Burst is written in bt[]
}

in weigh[0]= 0; // The waiting time for the first process is 0

for (i = 1; i <n; i ++) {
in weigh[i]= 0;
for (j = 0; j <i; j ++) {
in weigh[i]= Bt +[j]; // Waiting Time weather summary
}
}

printf (" nProcess  t  tBurst time  tWaiting Time  tTurnaround Time"); // Headboard

for (i = 0; i <n; i ++) {
tat[i]= bt[i]wt +[i]; // TurnAroundTime = BurstTime + WaitingTime
AVwt = wt +[i]; // AverageWaitingTime = AverageWaitingTime + WaitingTime
avtat + = tat[i]; // averageTurnAroundTime = AverageTurnAroundTime + TurnAroundTime
printf (" n P[%d] t  t% d  t  t% d  t  t% d ", i + 1, bt[i]WT[i]tat[i]); // Presentation of the data row of the table
}

AVwt / = i; // AverageWaitingTime = AverageWaitingTime / number of processes
avtat / = i; // averageTurnAroundTime = AverageTurnAroundTime / number of processes
printf (" n  nAverage Waiting Time:% d", avwt);
printf (" nAverage Turnaround Time:% d", avtat);

}

// ********************************************** ********************************************** ******
// ********************************************** ********************************************** ******
// ESCALONAMIENTO SJF
// ********************************************** ********************************************** *****
// ********************************************** ********************************************** ******

void sjf () {vb}
int n, bt[20]WT[20]tat[20], AVwt = 0, avtat = 0, i, j;
int lista_bt_ord[20], aux = 0, k = 0, search_process = 0;
printf ("Enter with the number of processes (maximum 20):"); // Process number entry
scanf ("% d", & n);
printf (" nBetween the processing time of the process n");

(i = 0; i <n; i ++) {// Fill the process burst
printf ("P[%d]: ", i + 1);
scanf ("% d", and bt[i]); // Burst is written in bt[]
}

lista_bt_ord[0] = bt[0]; // Enter the first burst in the ordered list
(i = 1; i <n; i ++) {// Reading of the bursts vector
(j = 0; j <= i; j ++) {// Insertion reading in the sorted list
yes (bt[i] < lista_bt_ord[j]){ // Verifica o burst for menor que algum que ja estiver na lista ele entra no lugar
            for(k=i; k>j; k -) {// Organize the list
lista_bt_ord[k] = list_bt_ord[k-1];
}
lista_bt_ord[j] = bt[i];
to break;
}} else if (j == i) {
lista_bt_ord[j] = bt[i]; // insert at the end of the vector if it is the highest
to break;
}
} // Close second for
} // Close first for

in weigh[0]= 0; // The waiting time for the first process is 0

for (i = 1; i <n; i ++) {
in weigh[i]= 0;
for (j = 0; j <i; j ++) {
in weigh[i]+ = List_bt_ord[j]; // Waiting Time weather summary
}
}



printf (" nProcess  t  tBurst time  tWaiting Time  tTurnaround Time"); // Headboard

for (i = 0; i <n; i ++) {
tat[i]= list_bt_ord[i]wt +[i]; // TurnAroundTime = BurstTime + WaitingTime
AVwt = wt +[i]; // AverageWaitingTime = AverageWaitingTime + WaitingTime
avtat + = tat[i]; // averageTurnAroundTime = AverageTurnAroundTime + TurnAroundTime
search_process = list_bt_ord[i];
(j = 0; j <n; j ++) {// check the process that contains this burst time
if (process_look == bt[j]) {
search_process = j;
to break;
}
}
printf (" n P[%d] t  t% d  t  t% d  t  t% d ", search_process + 1, list_bt_ord[i]WT[i]tat[i]); // Presentation of the data row of the table
}

AVwt / = i; // AverageWaitingTime = AverageWaitingTime / number of processes
avtat / = i; // averageTurnAroundTime = AverageTurnAroundTime / number of processes
printf (" n  nAverage Waiting Time:% d", avwt);
printf (" nAverage Turnaround Time:% d  n  n", avtat);

}

// ********************************************** ********************************************** ******
// ********************************************** ********************************************** ******
// SRTF SCALING
// ********************************************** ********************************************** *****
// ********************************************** ********************************************** ******

void srtf () {}
int n, tat[20], AVwt = 0, avtat = 0, i, j;
int int = 0, early_et_ = 0;

printf ("Enter total number od processes (maximum 20):"); // Process number entry
scanf ("% d", & n);

(i = 0; i <n; i ++) {// Fill the process burst
printf (" nBetween the process process burst  n");
printf ("P[%d]: ", i + 1);
processSRTF[i].name = i + 1;
scanf ("% d", and processSRTF[i].burst); // Burst is written
processSRTF[i].burstTotal = processSRTF[i].burst;
printf (" nBetween the process arrival time");
scanf ("% d", and processSRTF[i].chegada); // Process entry time

}

(i = 0; i)<100; i++){
    aux_pronto = verificaEntradaSRTF(i,n);
    if(aux_pronto > 0) {// If aux_pronto is greater than 0, some process entered that time of arrival
if (ready! = 0 && processSRTF[aux_pronto-1].burst < processoSRTF[pronto-1].burst){ //Se ja existe um processo sendo executado mas o que esta entrando tem burst menor
            pronto = aux_pronto; //muda o processo que entrou para ser executado
            executarProcessoSRTF(pronto,i,n); //executa processo que entrou
        }else if(pronto!=0 && processoSRTF[aux_pronto-1].burst >= processSRTF[pronto-1].burst) {// If a process already exists that is running but what has entered has a burst greater or equal
yes (processoSRTF[pronto-1].burst! = 0) {// Verify if the process that is still running has bursts to be processed
executeProcessoSRTF (ready i, n);
} Else {
(in the event of an error in the process)
yes (ready == 0) {
continue;
} Else {
executeProcessoSRTF (ready i, n);
}
}

} Else {
ready = soon_time;
executeProcessoSRTF (ready i, n);
}
}} else if (aux_pronto == 0 && listo! = 0) {
yes (processoSRTF[pronto-1].burst! = 0) {// Verify if the process that is still running has bursts to be processed
executeProcessoSRTF (ready i, n);
} Else {
(in the event of an error in the process)
yes (ready == 0) {
to break;
} Else {
executeProcessoSRTF (ready i, n);
}
}
}
(checkFimSRTF (n) == 0) {
to break;
}
}

printf (" nProcess  t  t Input Time  tBurst time  tWaiting Time  tTurnaround Time"); // Headboard

for (i = 0; i <n; i ++) {
tat[i]= processSRTF[i].burstTotal + processoSRTF[i].waitingTime; // TurnAroundTime = BurstTime + WaitingTime
AVwt + = processoSRTF[i].waitingTime; // AverageWaitingTime = AverageWaitingTime + WaitingTime
avtat + = tat[i]; // averageTurnAroundTime = AverageTurnAroundTime + TurnAroundTime
printf (" n P[%d] t  t% d  t  t  t% d  t  t% d  t  t% d ", processSRTF[i].name, processSRTF[i].chegada, processoSRTF[i].burstTotal, processSRTF[i].waitingTime, tat[i]); // Presentation of the data row of the table
}

AVwt / = i; // AverageWaitingTime = AverageWaitingTime / number of processes
avtat / = i; // averageTurnAroundTime = AverageTurnAroundTime / number of processes
printf (" n  nAverage Waiting Time:% d", avwt);
printf (" nAverage Turnaround Time:% d", avtat);

}

(), (), (), (), ()
int i, cont = 0;
(i = 0; i0) {
return 1;
} Else {
return 0;
}
}

int intEnaNovoProcesoSRTF (int n) {
int i, j, burst = 0, name = 0;
(i = 0; i 0 && processSRTF)[j].burst <burst) {f}
name = processSRTF[j].yam;
burst = processSRTF[j].burst;
}
}
return name;
}
}
return burst;
}

void verifyWaitingTimeSRTF (int currentTime, int n, int id) {
int i;
(i = 0; i)

void executeProcessoSRTF (int id, int time, int n) {
processSRTF[id-1].burst = processSRTF[id-1].burst – 1; // Decreases a time in the burst of the running process
checkWaitingTimeSRTF (time, n, id);
}

int interpreterEntranceSRTF (int time, int n) {
int ready = 0, i;
(i = 0; i)

// ********************************************** ********************************************** ******
// ********************************************** ********************************************** ******
// ROUND ROBIN STAGING
// ********************************************** ********************************************** *****
// ********************************************** ********************************************** ******
void roundrobin () {noun.
int n, quantum, tat[20], AVwt = 0, avtat = 0, i, j;
printf (" nBetween the number of processes (maximum 20): n"); // Process number entry
scanf ("% d", & n);
printf (" nDigit the CPU Time Quantum: n");
scanf ("% d", & quantum);

(i = 0; i <n; i ++) {// Fill the process burst
printf (" nBetween the processing time of the process  n");
printf ("P[%d]: ", i + 1);
processRR[i].name = i + 1;
scanf ("% d", and processoRR[i].burst); // Burst is written in the process structure
processRR[i].waitingTime = 0; // Waiting Time of each process starts with 0;
processRR[i].burstTotal = processRR[i].burst;
}

(i = 0; i) 0) {
executaProcessoRR (Quantum, n);
i = 0;
}
}


printf (" nProcess  t  tBurst time  tWaiting Time  tTurnaround Time"); // Headboard

for (i = 0; i <n; i ++) {
tat[i]= processRR[i].burstTotal + processoRR[i].waitingTime; // TurnAroundTime = BurstTime + WaitingTime
AVwt + = processoRR[i].waitingTime; // AverageWaitingTime = AverageWaitingTime + WaitingTime
avtat + = tat[i]; // averageTurnAroundTime = AverageTurnAroundTime + TurnAroundTime

printf (" n P[%d] t  t% d  t  t% d  t  t% d ", processRR[i].name, processoRR[i].burstTotal, processoRR[i].waitingTime, tat[i]); // Presentation of the data row of the table
}

AVwt / = i; // AverageWaitingTime = AverageWaitingTime / number of processes
avtat / = i; // averageTurnAroundTime = AverageTurnAroundTime / number of processes
printf (" n  nAverage Waiting Time:% d", avwt);
printf (" nAverage Turnaround Time:% d  n  n", avtat);

}

void executeProcessoRR (int quantum, int n) {
int i, j;
(i = 0; i 0) {}
(j = 0; j! = quantum; j ++) {// process that runs in quantum time
if (processRR[i].burst! = 0) {}
processRR[i].burst – = 1;
contaWaitingTimeRR (i, n);
} Else {
to break;
}
} // Close second for
} // Close if
} // Close first for
}

void accountWaitingTimeRR (current int, int n) {
int i, j;
(i = 0; i 0) {}
processRR[i].waitingTime + = 1; // Count the process wait time
}
}
}
}

// ********************************************** ********************************************** ******
// ********************************************** ********************************************** ******
// MULTILEVEL SCALING
// ********************************************** ********************************************** *****
// ********************************************** ********************************************** ******

multilevel void () {
int n, quantum, tat[20], AVwt = 0, avtat = 0, i, j;
printf (" nBetween the number of processes (maximum 20): n"); // Process number entry
scanf ("% d", & n);
printf (" nDigit the CPU Time Quantum for the Round Robin: n");
scanf ("% d", & quantum);

(i = 0; i <n; i ++) {// Fill the process burst
printf (" nBetween the processing time of the process  n");
printf ("P[%d]: ", i + 1);
Process[i].name = i + 1;
scanf ("% d", and process[i].burst); // Burst is written in the process structure
Process[i].waitingTime = 0; // Waiting Time of each process starts with 0;
Process[i].burstTotal = processM[i].burst;
Process[i].SelectionSelection = 0; // Type of scaling 0 is for round robin and 1 for JSF
}

(i = 0; i) 0) {
yes (process)[i].Selection == 0) {// First process of all is the RoundRobin
executaProcessoRRM (Quantum, n);
} else if (processM[i]......................................
executaProcessoJSFM (n);
}
i = 0;
}
}


printf (" nProcess  t  tBurst time  tWaiting Time  tTurnaround Time"); // Headboard

for (i = 0; i <n; i ++) {
tat[i]= process[i].burstTotal + process[i].waitingTime; // TurnAroundTime = BurstTime + WaitingTime
AVwt + = processM[i].waitingTime; // AverageWaitingTime = AverageWaitingTime + WaitingTime
avtat + = tat[i]; // averageTurnAroundTime = AverageTurnAroundTime + TurnAroundTime

printf (" n P[%d] t  t% d  t  t% d  t  t% d ", processM[i].name, process[i].burstTotal, process[i].waitingTime, tat[i]); // Presentation of the data row of the table
}

AVwt / = i; // AverageWaitingTime = AverageWaitingTime / number of processes
avtat / = i; // averageTurnAroundTime = AverageTurnAroundTime / number of processes
printf (" n  nAverage Waiting Time:% d", avwt);
printf (" nAverage Turnaround Time:% d  n  n", avtat);

}

void runningProcesssoJSFM (int n) {
int lista_JSF[20], list_JSF_ord[20]I J K;
int int = 0;

(i = 0; i) 0 && procesM[i].typeEscalonamento == 1) {
list_JSF[insere] = processM[i].burst;
++ inserts;
}
}

list_JSF_ord[0] = list_JSF[0];

(i = 1, i <insert, i ++) {// Read the bursts vector
(j = 0; j <= i; j ++) {// Insertion reading in the sorted list
yes (list_JSF[i] < lista_JSF_ord[j]){ // Verifica o burst for menor que algum que ja estiver na lista ele entra no lugar
            for(k=i; k>j; k -) {// Organize the list
list_JSF_ord[k] = list_JSF_ord[k-1];
}
list_JSF_ord[j] = list_JSF[i];
to break;
}} else if (j == i) {
list_JSF_ord[j] = list_JSF[i]; // insert at the end of the vector if it is the highest
to break;
}
} // Close second for
} // Close first for


(i = 0; i <insert; i ++) {// OrderList
for (j = 0; j 0) {
Process[j].burst - = 1;
(k = 0; k) 0) {
Process[k].waitingTime + = 1;
}
}
}
to break;
}
}
}

}

void executingRRMProcess (int quantum, int n) {
int i, j;
(i = 0; i 0) {}
yes (process)[i]) .burst> quantum) {
Process[i].Select the value = 1;
}
(j = 0; j! = quantum; j ++) {// process that runs in quantum time
if (processM[i].burst! = 0) {}
Process[i].burst – = 1;
contaWaitingTimeRRM (i, n);
} Else {
to break;
}
} // Close second for
} // Close if
} // Close first for
}

void accountWaitingTimeRRM (current int, int n) {
int i, j;
(i = 0; i 0) {}
Process[i].waitingTime + = 1; // Count the process wait time
}
}
}
}