Created
October 27, 2022 00:15
-
-
Save tienminhvy/239823742c8aca42649c951399c7e24a to your computer and use it in GitHub Desktop.
Gantt chart generator for C programing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void print_gantt_chart(Process p[], int n) | |
{ | |
int i, j; | |
// print top bar | |
printf(" "); | |
for(i=0; i<n; i++) { | |
for(j=0; j<p[i].burst_time; j++) printf("--"); | |
printf(" "); | |
} | |
printf("\n|"); | |
// printing process id in the middle | |
for(i=0; i<n; i++) { | |
for(j=0; j<p[i].burst_time - 1; j++) printf(" "); | |
printf("P%d", p[i].pid); | |
for(j=0; j<p[i].burst_time - 1; j++) printf(" "); | |
printf("|"); | |
} | |
printf("\n "); | |
// printing bottom bar | |
for(i=0; i<n; i++) { | |
for(j=0; j<p[i].burst_time; j++) printf("--"); | |
printf(" "); | |
} | |
printf("\n"); | |
// printing the time line | |
printf("0"); | |
for(i=0; i<n; i++) { | |
for(j=0; j<p[i].burst_time; j++) printf(" "); | |
if(p[i].turnaround_time > 9) printf("\b"); // backspace : remove 1 space | |
printf("%d", p[i].turnaround_time); | |
} | |
printf("\n"); | |
} | |
// Full source-code from https://educativesite.com/first-come-first-serve-fcfs-scheduling-algorithm-program-code-in-c-with-gantt-chart/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment