View Single Post
Old 21-06-2005, 21:03   #3
vanhalen
Junior Member
 
Iscritto dal: Jun 2005
Messaggi: 15
[c*de]
/* Esame*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SIZE 20

struct count {
char nome[14];
int n;
};
typedef struct count lista;

int RicercaEsaustiva(lista *,char *);



main(){

lista persone[SIZE];
int i;
for(i=0; i<=SIZE-1; i++){
strcpy(persone[i].nome,"");
persone[i].n=0;
}

char parola[14];
FILE *fPtr;
int resp=0;
i=0;
if ((fPtr=fopen("testo.h", "r")) == NULL)
printf("Non posso aprire il file\n");
else{

while (!feof(fPtr)){
fscanf(fPtr, "%s", parola);
if((resp=RicercaEsaustiva(persone, parola)) != -1)
persone[resp].n=persone[resp].n + 1;

else{
strcpy(persone[i].nome,parola);
persone[i++].n=1;

}

}

for(i=0; i<=SIZE-1;i++)
printf("%-14s%10d\n", persone[i].nome, persone[i].n);
}
system("pause");
return 0;
}


int RicercaEsaustiva(lista *p, char *str){
int u=0;
for (u=0; u<=SIZE-1; u++){
if (!strncmp(p[u].nome,str, 14 ))
return u;
}
return -1;
}

[/c*de] (* = o)


Scusami......
vanhalen è offline   Rispondi citando il messaggio o parte di esso