#include #include #include #include int main(int argc, char **argv) { if(argc < 2) { printf("Program requires file argument at the least.\n"); return 1; } else if(argc > 4) { printf("Program takes 3 arguments max.\n"); return 1; } int index = 0; if(argc > 2) index = atoi(argv[2]); int fileNum = atoi(argv[1]); char fileName[20]; snprintf(fileName, 19, "storage/%d.txt", fileNum); FILE *f = fopen(fileName, "r"); if(!f) { printf("Error opening file to read.\n"); return 1; } int length = 0; char c = getc(f); while(c != EOF) { if(c == '\n') length++; c = getc(f); } if(length <= index) { printf("Index is bigger than file length.\n"); return 1; } if(argc == 4) { int uInd = atoi(argv[3]) + index; if(uInd < length) length = uInd; } FILE *graph = popen("gnuplot", "w"); if(!graph) { printf("Error opening gnuplot.\n"); return 1; } fprintf(graph, "plot '-'\n"); fseek(f, 0, SEEK_SET); c = getc(f); char buffer[50]; snprintf(buffer, 49, "%d ", index++); char append[2] = {' ', '\0'}; while(c != EOF && index <= length) { append[0] = c; strcat(buffer, append); if(c == '\n') { fprintf(graph, "%s", buffer); snprintf(buffer, 49, "%d ", index++); } c = getc(f); } fprintf(graph, "e\n"); fflush(graph); sleep(-1); }