JoBlack Posted May 21, 2006 at 03:00 PM Report #28616 Posted May 21, 2006 at 03:00 PM Olá pessoal No prg que estou a fazer pedem-me que faça listagens de autores por 'nome' e por 'nacionalidade'. Já andei a ver se conseguia alguma coisa mas não consegui chegar a conclusões. O código que fiz e que coloco abaixo só me lista pela ordem natural com que foram inseridos os dados, ou seja, pelo nr. Alguém me pode dar uma ajudita? Obrigado. Parte do código que interessa: #define FICH3 "Autores.dat" struct autor { int nr; char nome[50], nacion[20]; } AUT; FILE *fa; void ad_autor() { fa=fopen(FICH3,"a+"); system("CLS"); while(fread(&AUT,sizeof(AUT),1,fa)==1) ; AUT.nr+=1; fseek(fa,0,SEEK_END); printf("\n\t Nome: "); fflush(stdin); gets(AUT.nome); AUT.nome[49]=' '; AUT.nome[50]='\0'; printf("\n\t Nacionalidade: "); fflush(stdin); gets(AUT.nacion); AUT.nacion[19]=' '; AUT.nacion[20]='\0'; fwrite(&AUT,sizeof(AUT),1,fa); } void List_autor() { fa=fopen(FICH3,"r"); system("cls"); rewind(fa); printf("\n Nr Nome Nacionalidade"); printf("\n ---------------------------------------------------"); while(fread(&AUT,sizeof(AUT),1,fa)==1) { printf("\n\n %-5d%-32s%-20s", AUT.nr,AUT.nome,AUT.nacion); } getch(); fclose(fa); }
brink@ero Posted May 21, 2006 at 03:13 PM Report #28619 Posted May 21, 2006 at 03:13 PM Dá uma vista de olhos nesta thread: http://www.portugal-a-programar.pt/index.php?showtopic=1743 Cumpr. bk@ero 😄
JoBlack Posted May 21, 2006 at 03:30 PM Author Report #28620 Posted May 21, 2006 at 03:30 PM Obrigado, já a tinha visto mas não consegui implementar o código nem sequer perceber como funciona...
Rui Carlos Posted May 23, 2006 at 12:03 PM Report #29075 Posted May 23, 2006 at 12:03 PM Pelo que percebi estás a guardar as informações lidas num ficheiro. Não seria melhor guardar numa lista/árvore (ordenada)? Rui Carlos Gonçalves
untouchables Posted May 23, 2006 at 07:25 PM Report #29165 Posted May 23, 2006 at 07:25 PM Pelo que percebi estás a guardar as informações lidas num ficheiro. Não seria melhor guardar numa lista/árvore (ordenada)? offtopic: MCC é o curso, o resto é recurso 👍
Warrior Posted May 23, 2006 at 08:58 PM Report #29194 Posted May 23, 2006 at 08:58 PM Lê todo o ficheiro para uma lista (ordenada) e depois volta a transpo-la para o ficheiro.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now