i'm trying implement shortest seek time first (sstf) algorithm in linux command line. commandline read track values following line:
./disksed 53 98 183 37 122 14 124 65 67
and print following report:
sstf: start:53 65:12 67:2 37:30 14:23 98:84 122:24 124:2 183:59 total:236
am on right track @ all? i'm not getting correct values, , don't know how proceed. below code far. appreciated.
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { const int array_size = 9; int sstd[array_size]; int total2 = 0; int temp; printf("\nsstf: start:"); printf("%s", argv[1]); printf(" "); (int = 1; < 9; i++) { if (strtol(argv[i + 1], null, 10) - strtol(argv[i], null, 10) < 0) total2 += (abs(strtol(argv[i + 1], null, 10) - strtol(argv[i], null, 10))); else total2 += (strtol(argv[i + 1], null, 10) - strtol(argv[i], null, 10)); temp = strtol(argv[i + 1], null, 10); argv[i + 1] = argv[i + 2]; argv[i + 2] = (char)temp; sstd[i] = strtol(argv[i + 1], null, 10); printf("%d", sstd[i]); printf(":"); //print difference? printf(" "); } printf("total:"); printf("%d", total2); printf("\n"); return 0; }
Comments
Post a Comment