Whiteangel Posted December 4, 2015 at 06:42 PM Report #590388 Posted December 4, 2015 at 06:42 PM Boas pessoal, estou a tentar eliminar um registo de um ficheiro, mas não está eliminar, podem ajudar? void Eliminar() { char estado = 'A'; int numero; int n; printf("Numero do aluno?"); scanf("%d", &numero); fich = fopen("alunos.DAT","r+b"); if (fich== NULL) { printf("\nErro ao abrir o ficheiro\n"); return; } fseek(fich, 0, SEEK_END); n = ftell(fich) / sizeof(a); fseek(fich, 0, SEEK_SET); int pos = 0; int i; for (i = 0; i < n; i++) { fread(&a, sizeof(a), 1, fich); if (estado == 'A') if (a.codigo == numero) { pos = i; printf("%d\n",a.codigo); printf("%s\n",a.nome); printf("%s\n",a.curso); break; } } if (i < n) { int eliminar; printf("Pretende eliminar o aluno?\n"); printf(" 1 - Sim 0 - Nao\n"); scanf("%d", & eliminar); if (eliminar == 0){ return; }else { fseek(fich, pos * sizeof(a), SEEK_END); fread(&a, sizeof(a), 1, fich); fseek(fich, pos * sizeof(a), SEEK_SET); fwrite(&a, sizeof(a), 1, fich); printf("O Aluno foi eliminado com sucesso\n"); } fclose(fich); } }
HappyHippyHippo Posted December 4, 2015 at 07:29 PM Report #590391 Posted December 4, 2015 at 07:29 PM explica o que estás a fazer em cada uma das seguintes linhas : fseek(fich, pos * sizeof(a), SEEK_END); fread(&a, sizeof(a), 1, fich); fseek(fich, pos * sizeof(a), SEEK_SET); fwrite(&a, sizeof(a), 1, fich); IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Whiteangel Posted December 6, 2015 at 04:27 PM Author Report #590417 Posted December 6, 2015 at 04:27 PM explica o que estás a fazer em cada uma das seguintes linhas : fseek(fich, pos * sizeof(a), SEEK_END); fread(&a, sizeof(a), 1, fich); fseek(fich, pos * sizeof(a), SEEK_SET); fwrite(&a, sizeof(a), 1, fich); Pretendo calcular o numero de registros fazendo a respectiva leitura
HappyHippyHippo Posted December 6, 2015 at 07:46 PM Report #590424 Posted December 6, 2015 at 07:46 PM explica o que estás a fazer em cada uma das seguintes linhas : IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
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