T
Tcc
Hi All,
Assume there are some data in "a.txt":
e.g.
ABC
DEF<--------duplicate
GHI
DEF<--------duplicate
JKL
MNO
PQR
STU<--------duplicate
STU<--------duplicate
STU<--------duplicate
VWX
YZA
XYZ
XYZ
CAD
YZA
KLS
GAE
PQR
GAE
ABC
SAC
MTF
I would like to reduce the duplication of data so that to form:
e.g.
ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
YZA
XYZ
CAD
KLS
GAE
SAC
MTF
Here are my codes, but seems they aren't work:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct H {
char name[5];
int l;
};
H r[50];
int main() {
char a[5];
int count =0;
FILE *fin = fopen("a.txt", "r");
for(i=0; !feof(fin); i++) {
//Set as Null
strcpy(r.name, "N");
fscanf(f, "%s", a);
for(i=0; i<50 ; i++) {
// Check for null
if(strcmp(r.name, "N") == 0) {
strcpy(r.name, a);
i=50;
break;
} else {
for(i=0; i<50 ; i++) {
if(strcmp(r.name, a) == 0) {
count++;
i=50+i;
} else {
for(i=0; i<50 ; i++) {
if(strcmp(r[i+1].name, a) == 0) {
count++;
i=50+i;
} else {
i++;
strcpy(r[i+count].name, a);
}
}
}
}
}
}
}
How should I improve those so that to generate data with no duplication?
Please help.
THANKS ALL!
Assume there are some data in "a.txt":
e.g.
ABC
DEF<--------duplicate
GHI
DEF<--------duplicate
JKL
MNO
PQR
STU<--------duplicate
STU<--------duplicate
STU<--------duplicate
VWX
YZA
XYZ
XYZ
CAD
YZA
KLS
GAE
PQR
GAE
ABC
SAC
MTF
I would like to reduce the duplication of data so that to form:
e.g.
ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
YZA
XYZ
CAD
KLS
GAE
SAC
MTF
Here are my codes, but seems they aren't work:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct H {
char name[5];
int l;
};
H r[50];
int main() {
char a[5];
int count =0;
FILE *fin = fopen("a.txt", "r");
for(i=0; !feof(fin); i++) {
//Set as Null
strcpy(r.name, "N");
fscanf(f, "%s", a);
for(i=0; i<50 ; i++) {
// Check for null
if(strcmp(r.name, "N") == 0) {
strcpy(r.name, a);
i=50;
break;
} else {
for(i=0; i<50 ; i++) {
if(strcmp(r.name, a) == 0) {
count++;
i=50+i;
} else {
for(i=0; i<50 ; i++) {
if(strcmp(r[i+1].name, a) == 0) {
count++;
i=50+i;
} else {
i++;
strcpy(r[i+count].name, a);
}
}
}
}
}
}
}
How should I improve those so that to generate data with no duplication?
Please help.
THANKS ALL!