Hi guy, I have been teaching myself how to write C programming code, right now am learning the Round Robin Sheduling algorithm, below is the code that i have managed to write, its the basic but i could do with your help or your direction with how to do the following.
I want my program to have an option via a menu to request the user input of Number of processes N and then for each process the Arrival time AT, the number of units of CPU time required NUT. Basically i want to be able to
1.function read data file that will add a node onto a linklist
2.move node toplist to bottom of linklist
3.move node from one list
4.function scan list to display
5.Remove the node.
#include <stdio.h>
#include <stdlib.h>
struct nodedef{
char label;
int NUT;
char status;
int prio;
struct nodedef *next;
};
typedef struct nodedef procdef;
main(){
FILE *fptr;
int AT;
procdef *new, *curr;
int i,nl, np;
fptr = fopen("data.txt","r");
fscanf(fptr,"%d",&np);
fscanf(fptr,"%c",&nl);
new = (procdef *) malloc(sizeof(procdef));
fscanf(fptr,"%c",&new->label);
fscanf(fptr,"%d",&new->NUT);
fscanf(fptr,"%d",&AT);
fscanf(fptr,"%c",&nl);
new->status = 'W';
new->prio = 0;
new->next = NULL;
curr = new;
//loop
for(i=0;i<np-1;i++){
curr->next = (procdef *) malloc(sizeof(procdef));
curr = curr->next; //move to next node
fscanf(fptr,"%c",&curr->label);
fscanf(fptr,"%d",&curr->NUT);
fscanf(fptr,"%d",&AT);
fscanf(fptr,"%c",&nl);
curr->status = 'W';
curr->prio = 0;
curr->next = NULL;
}
curr = new; //points to 1st node
for(i=0;i<np;i++){
printf("%c %d %c %d %p\n",curr->label,curr->NUT,curr->status,curr->prio,curr->next);
curr = curr->next;
}
}