/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include #include #include #include int main () { int cnt = 0; char *cols[43]; size_t n = 0; FILE *fp = fopen ("input.txt", "r"); FILE *fp2= fopen ("output.txt", "a"); if (fp == NULL ) { perror ("Unable to open file!"); exit (1); } char *line2 = NULL; size_t len = 0; clock_t begin = clock(); /* here, do your time-consuming job */ while (getline (&line2, &len, fp) != -1) { n = 0; if (len > 43) for (char *p = strtok (line2, ";"); p; p = strtok (NULL, ";")) { if (n < 4) fprintf (fp2,"%s;", p); else if (n > 3 && n < 42) { for (int x = n - 1; x > 2; x--) { if (strcmp (cols[x], p) == 0) break; else if (x < 4) fprintf (fp2,"%s", p); } fprintf (fp2,";"); } cols[n++] = p; if (n > 42) break; } fprintf (fp2,"\n"); } clock_t end = clock(); double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf ("%f\n",time_spent); return 0; }