#include #include #include #include #include #include #include #include #define DAN 69 #define NOC 420 #define JUTRO 1337 int main(int argc, char *argv[]) { if(argc != 1+6) { fprintf(stderr, "usage: %s / (direktorij se mora OBVEZNO končati z /)\n", argv[0]); return 1; } char *delim = argv[6]; int kolikokrat = atoi(argv[1]); int stolpec = atoi(argv[5]); double vrednost = atof(argv[2]); double koliksenvzpon = atof(argv[3]); char **list; size_t i, len; char line[1337]; int iter = 0; int status = DAN; fgets(line, 1337, stdin); line[strcspn(line, "\n")] = 0; int daynum = 0; char daynum_str[16]; char path[PATH_MAX+1]; strlcpy(path, argv[4], sizeof(path)); sprintf(daynum_str, "%d", daynum); strlcat(path, daynum_str, sizeof(path)); strlcat(path, ".csv", sizeof(path)); FILE * file = fopen_mkdir(path, "w"); int zaporednih_vrednost_ali_manj = 0; while(1) { explode(line, delim, &list, &len); if(status == DAN && atof(list[stolpec]) <= vrednost) { zaporednih_vrednost_ali_manj++; } else { zaporednih_vrednost_ali_manj = 0; } if(zaporednih_vrednost_ali_manj >= kolikokrat) { // fprintf(stderr, "status NOC za %d. dan\n", daynum); // realised it worked before status = NOC; } if(status == NOC && atof(list[stolpec]) >= vrednost+koliksenvzpon) { status = DAN; daynum++; strlcpy(path, argv[4], sizeof(path)); sprintf(daynum_str, "%d", daynum); strlcat(path, daynum_str, sizeof(path)); strlcat(path, ".csv", sizeof(path)); file = fopen_mkdir(path, "w"); zaporednih_vrednost_ali_manj = 0; } for(int j = 0; j < len; j++) { if(j == len-1) { fprintf(file, "%s", list[j]); } else { fprintf(file, "%s%s", list[j], delim); } } fprintf(file, "\n"); /* free list */ for(i = 0; i < len; ++i) { free(list[i]); } free(list); fgets(line, 1337, stdin); if(feof(stdin)) { break; } // fprintf(stderr, "d: %s", line); line[strcspn(line, "\n")] = 0; iter++; } return 0; }