Schupp

Testchar

May 18th, 2021
476
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************
  2.  
  3.                             Online C Compiler.
  4.                 Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13.  
  14. int
  15. main ()
  16. {
  17.   int cnt = 0;
  18.   char *cols[43];
  19.   size_t n = 0;
  20.   FILE *fp = fopen ("input.txt", "r");
  21.   FILE *fp2= fopen ("output.txt", "a");
  22.   if (fp == NULL )
  23.     {
  24.       perror ("Unable to open file!");
  25.       exit (1);
  26.     }
  27.   char *line2 = NULL;
  28.   size_t len = 0;
  29. clock_t begin = clock();
  30.  
  31. /* here, do your time-consuming job */
  32.  
  33.   while (getline (&line2, &len, fp) != -1)
  34.     {
  35.       n = 0;
  36.       if (len > 43)
  37.     for (char *p = strtok (line2, ";"); p; p = strtok (NULL, ";"))
  38.       {
  39.         if (n < 4)
  40.           fprintf (fp2,"%s;", p);
  41.         else if (n > 3 && n < 42)
  42.           {
  43.         for (int x = n - 1; x > 2; x--)
  44.           {
  45.             if (strcmp (cols[x], p) == 0)
  46.               break;
  47.             else if (x < 4)
  48.               fprintf (fp2,"%s", p);
  49.           }
  50.         fprintf (fp2,";");
  51.           }
  52.         cols[n++] = p;
  53.         if (n > 42)
  54.           break;
  55.       }
  56.       fprintf (fp2,"\n");
  57.     }
  58.    
  59. clock_t end = clock();
  60. double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  61. printf ("%f\n",time_spent);
  62.   return 0;
  63. }
  64.  
RAW Paste Data