Schupp icon

Testchar

Schupp | PRO | 05/18/21 08:53:06 AM UTC | 0 ⭐ | 888 👁️ | Never ⏰ | []
C |

1.43 KB

|

None

|

0 👍

/

0 👎

/******************************************************************************
 
                            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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
 
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;
}
 

Comments