File: removeduplicates.cpp

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (30 lines) | stat: -rw-r--r-- 484 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char** argv)
{
  if (argc<3)
    exit(-1);
  FILE* fin = fopen(argv[1],"rb");
  if (!fin) exit(-1);
  FILE* fout = fopen(argv[2],"wb");
  if (!fout) exit(-1);
  
  char prev[8192];
  prev[0]=0;
  char buf[8192];
  while (fgets(buf,8192,fin) && !feof(fin))
  {
    if (strcmp(buf,prev))
    {
      fprintf(fout,"%s",buf);
      strcpy(prev,buf);
    }
  }
  
  fclose(fin);
  fclose(fout);
  return 0;
}