#include #include #include #include #include #include #include #include #define POT 0 #define CAS 1 #define JUTRO 1337 int main(int argc, char *argv[]) { if(argc != 1+3) { fprintf(stderr, "uporaba: %s <čas stolpec 0-999>\n", argv[0]); return 1; } char *delim = argv[1]; int stolpec[2]; stolpec[POT] = atoi(argv[2]); stolpec[CAS] = atoi(argv[3]); char **list; size_t i, len; char line[1337]; int iter = 0; double *values; fgets(line, 1337, stdin); line[strcspn(line, "\n")] = 0; while(1) { explode(line, delim, &list, &len); if(iter == 0) { values = malloc(sizeof(double) * 2); // len); // potrebujemo prostor samo za čas in pot } for(int j = 0; j < len; j++) fprintf(stdout, "%s%s", list[j], delim); fprintf(stdout, "%f\n", ( atof(list[stolpec[POT]]) - values[POT] ) / ( atof(list[stolpec[CAS]]) - values[CAS] ) ); values[CAS] = atof(list[stolpec[CAS]]); values[POT] = atof(list[stolpec[POT]]); /* 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++; } free(values); return 0; }