Hi,
your code was terribly indented, almost unreadable.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#define MAXLAND 10
typedef struct
{
char namn[4];
Quote:
}test;
int main(void){
FILE *fil;
test Ttest[MAXLAND],Ttemp[MAXLAND];
int k=0,counter=0,ej_lika,m,stycken,a;
fil=fopen("land.dat","r");
if(!fil){
printf("ERROR open file!");
exit(1);
}
fscanf(fil,"%d",&stycken);
while(!feof(fil)){
fscanf(fil,"%s",&Ttest[k].namn);
k++;
}
fclose(fil);
for(k=0;k<=MAXLAND;k++)
Ttemp[k].namn==NULL; /* this makes no sense !!!! */
/' Can i do this different??*/
for(k=0;k<=stycken-1;k++){
ej_lika=0;
for(m=0;m<=stycken-1;m++){
if(strcmp(Ttest[k].namn,Ttemp[m].namn)!=0)
ej_lika++;
if(ej_lika==stycken){
strcpy(Ttemp[counter].namn,Ttest[k].namn);
ej_lika=0;
counter++;
break;
}
}
}
/*check the result.*/
for(k=0;k<counter;k++)
printf("%s\n",Ttemp[k].namn);
getch();
return 0;
Quote:
} /* this was missing !!!!! */
Some comments:
* Since Ttemp is not initialized when used first, the results are
completely undefined.
* If you want to eliminate duplicate entries, then you are not far away
from a correct solution. I think if you solve the problem with the
missing initialisation of Ttemp, then it should be almost done. You
should know how to copy the empty string "" to a char array? Hint, Hint.
HTH
Bernd Strieder
--