Anasimoes19988 0 Report post Posted September 30, 2015 será possível me ajudar a ver o que se passa com este código pois da me erro a introduzir e listar alunos. obrigada desde já abraços #include <stdio.h> #include <stdlib.h> /* SUBPROGRAMAS */ void boasVindas(); void menuPrincipal(); int opcaoMenuPrincipal(); void vizualizarAluno(); void adicionarAluno(); void editarAluno(); void eliminarAluno(); void mensagemErro(); void opcaoVoltarMenuInicial(); void fimPrograma(); /* REGISTO DE UM ALUNO */ typedef struct aluno{ int numero; char nome[40]; int idade; char sexo[15]; char turma[20]; char localidade[100]; }aluno; /* DADOS DE 1 ALUNO*/ /* INICIO DO PROGRAMA */ int main(){ int menu_Principal = 0; boasVindas(); do{ menuPrincipal(); menu_Principal = opcaoMenuPrincipal(); switch(menu_Principal){ case 1: vizualizarAluno();break; case 2:adicionarAluno();break; case 3:editarAluno();break; case 4:eliminarAluno();break; case 0:fimPrograma();break; default:mensagemErro(); } } while(menu_Principal != 0); return 0; system("PAUSE"); } void boasVindas(){ system("color 5F"); printf(""); printf("\n\n\n\n\n\t SISTEMA DE GESTAO DE BASE DE DADOS DOS ALUNOS \n"); printf(""); printf("\n\n\n\t BEM VINDO!!!!! \n"); _sleep(5000); -system("CLS"); printf("\n\n\n\n\n\t TRABALHO ELABORADO POR :ANA SIMOES E DANIELA CARVALHO\n"); printf(""); printf("\n\n\n\n\n\t DISCIPLINA DE :lINGUAGEM DE PROGRAMACAO\n"); _sleep(6000); system("CLS"); printf("\n\n\n\t SISTEMA DE GESTAO DE \n"); printf(""); printf ("\n\n\n\n\n\t BASE DE DADOS DOS ALUNOS\\AS"); _sleep(4000); system("CLS"); printf("\n\n\n\t AGUARDE A ABERTURA DO PROGRAMA \n"); printf("\n\n\n\t . \n"); _sleep(4000); system("CLS"); printf("\n\n\n\t AGUARDE A ABERTURA DO PROGRAMA \n"); printf("\n\n\n\t .. \n"); _sleep(3000); system("CLS"); printf("\n\n\n\t AGUARDE A ABERTURA DO PROGRAMA \n"); printf("\n\n\n\t ... \n"); _sleep(2000); system("CLS"); printf("\n\n\n\t AGUARDE A ABERTURA DO PROGRAMA \n"); printf("\n\n\n\t . \n"); _sleep(2000); system("CLS"); printf("\n\n\n\t AGUARDE A ABERTURA DO PROGRAMA \n"); printf("\n\n\n\t .. \n"); _sleep(2000); system("CLS"); printf("\n\n\n\t AGUARDE A ABERTURA DO PROGRAMA \n"); printf("\n\n\n\t ... \n"); system("CLS"); } void menuPrincipal(){ system("CLS"); fflush(stdin); printf(""); printf("\n\n\n\t SISTEMA DE GESTAO DE BASE DE DADOS DOS ALUNOS \n"); printf(""); printf(" M E N U P R I N C I P A L \n"); printf(""); printf("\n\n\n\t 1 - LISTA DOS ALUNOS\\AS INSERIDOS\\AS \n"); printf(""); printf("\n\n\n\t 2 - INTRODUZIR UM NOVO ALUNO\\A \n"); printf(""); printf("\n\n\n\t 3 - EDITAR DADOS DE UM ALUNO\\A \n"); printf(""); printf("\n\n\n\t 4 - ELIMINAR ALUNO\\A \n"); printf(""); printf("\n\n\n\t 0 - SAIR DA APLICACAO \n"); printf(""); fflush(stdin); } int opcaoMenuPrincipal(){ int opcaoMenu = 0; printf(""); printf("\n\n\n\t ESCOLHA UMA OPCAO: "); scanf("%d", &opcaoMenu); return (opcaoMenu); } void mensagemErro(){ system("CLS"); printf("\n\n\n"); printf("Erro a opcao nao existe!!!!!"); printf(" tente outra opcao"); _sleep(1500); printf("\n"); menuPrincipal(); } void opcaoVoltarMenuInicial(){ int opcao = 0; printf("\n\n\n\t Escreve \"0\" Para voltares novamente menu principal"); printf(""); printf("\n\n\n\t Escolher opcao "); scanf("%d", &opcao); if(opcao < 1){ menuPrincipal(); } else { printf("\n\n\n\n\t Escreve \"0\" Para voltares novamente menu principal"); _sleep(1999); system("cls"); opcaoVoltarMenuInicial(); } } void vizualizarAluno(){ FILE *verAluno; aluno student; char nameFile[40]; system("CLS"); printf(""); fflush(stdin); printf(""); printf("\n\n\n\t INTRODUZIR O NOME DO ALUNO\\A \n\n"); printf(""); printf(" NOME DO ALUNO\\A: "); gets(nameFile); strcat(nameFile, ".txt"); if((verAluno = fopen(nameFile, "AB")) == NULL ){ printf("\n\n\n\t NAO E POSSIVEL ENCONTAR O FICHEIRO DO ALUNO\A... TENTE NOVAMENTE \n"); } else { printf("\n\n\n\t O FICHEIRO DO ALUNO\A FOI ENCONTRADO \n"); if(fread(&student, sizeof(aluno), 5 , verAluno ) == 0 ){ printf("\n\n\n\t NAO FOI POSSIVEL LER O FICHEIRO ARMAZENADO...TENTE NOVAMENTE \n"); }else { printf(""); printf("\n\n\n\t VIZUALIZACAO DOS DADOS INTRODUZIDOS \n\n"); printf(""); printf(" NUMERO: %d \n", student.numero); printf(""); printf(" NOME: %s \n", student.nome); printf(""); printf(" TURMA: %s \n", student.turma); printf(""); printf(" IDADE: %d \n", student.idade); printf(""); printf(" LOCALIDADE: %s \n", student.localidade); printf(""); printf(" SEXO: %s \n", student.sexo); printf(""); }} if(fclose(verAluno) == EOF ){ printf("\n\n\n\t NAO FOI POSSIVEL FECHAR O FICHEIRO DE ARMAZENAMENTO\n"); } else { printf("\n\n\n\n\t O FICHEIRO DE ARMAZENAMENTO FOI FECHADO COM SUCESSO\n"); } opcaoVoltarMenuInicial(); } void adicionarAluno(){ FILE *novoAluno; aluno student; char nameFile[40]; int opcao = 0; system("CLS"); printf(""); fflush(stdin); printf(""); printf(" INTRODUZIR UM NOVO ALUNO\\A \n\n"); printf(""); printf(" NUMERO DO ALUNO\\A : "); scanf("%d", &student.numero); printf(""); fflush(stdin); printf(" NOME DO ALUNO\\A : "); gets(student.nome); printf(""); fflush(stdin); printf(" TURMA DO ALUNO\\A : "); gets(student.turma); printf(""); fflush(stdin); printf(" IDADE DO ALUNO\\A : "); scanf("%d", &student.idade); printf(""); fflush(stdin); printf(" LOCALIDADE DO ALUNO\\A : "); gets(student.localidade); printf(""); fflush(stdin); printf(" SEXO DO ANUNO\\A : "); gets(student.sexo); printf(""); char nome[40]; strcat(nome, student.nome); strcat(nome, ".txt"); system("CLS"); if((novoAluno = fopen(nome, "a")) == NULL ){ printf("\n\n\n\n\t NAO E POSSIVEL CRIAR UM NOVO ALUNO\\A!!! \n"); _sleep(1000); } if(fwrite(&student, sizeof(aluno), 1 , novoAluno) != 1 ){ printf("\n\n\n\n\t OS DADOS NAO FORAM GUARDADOS \n"); _sleep(1500); } else { printf("\n\n\n\n\t O PROGRAMA ESTA PRONTO PARA GUARDAR O ALUNO\\A !!!! \n"); _sleep(1500); } if(fclose(novoAluno) == 0){ printf("\n\n\n\t TODOS OS DADOS DO ALUNO\\A FORAM GUARDADOS COM SUCESSO \n"); _sleep(1500); } else { printf("\n\n\n\t ERRO AO GUARDAR DOS ALUNOS\\AS \n"); _sleep(1000); } printf("\n"); system("CLS"); printf(""); printf("\n\n\n\n\t VIZUALIZACAO DOS DADOS INTRODUZIDOS \n\n"); printf(""); printf(" NUMERO: %d \n", student.numero); printf(""); printf(" NOME: %s \n", student.nome); printf(""); printf(" TURMA: %s \n", student.turma); printf(""); printf(" IDADE: %d \n", student.idade); printf(""); printf(" LOCALIDADE: %s \n", student.localidade); printf(""); printf(" SEXO: %s \n", student.sexo); printf(""); printf(""); opcaoVoltarMenuInicial(); } void editarAluno(){ FILE *editarAluno; aluno student; char nome[40]; int opcao = 0; system("CLS"); printf(""); fflush(stdin); printf(""); printf("\t EDITAR DADOS DE UM ALUNO\\A \n\n"); printf(""); printf(" NOME DO ALUNO: "); gets(nome); strcpy(student.nome, nome); fflush(stdin); printf(""); strcat(nome, ".txt"); if((editarAluno = fopen(nome, "w")) == NULL ){ printf("\n\n\n\t NAO E POSSIVEL ENCONTRAR O FICHEIRO DO ALUNO\\A \n"); } else { printf("\n\n\n\t O FICHEIRO DO ALUNO\A FOI ENCONTRADO \n"); _sleep(3000); system("CLS"); printf(""); printf("\\n\n\n\n\t REINTRODUZIR DADOS DO ALUNO \n\n"); printf(""); printf(" NUMERO DO ALUNO : "); scanf("%d", &student.numero); printf(""); fflush(stdin); printf(" NOME DO ALUNO : "); gets(student.nome); printf(""); fflush(stdin); printf(" TURMA DO ALUNO : "); gets(student.turma); printf(""); fflush(stdin); printf(" IDADE DO ALUNO : "); scanf("%d", &student.idade); printf(""); fflush(stdin); printf(" LOCALIDADE DO ALUNO : "); scanf("%s", &student.localidade); printf(""); fflush(stdin); printf(" SEXO DO ANUNO : "); gets(student.sexo); printf(""); strcat(nome, student.nome); strcat(nome, ".txt"); system("CLS"); if(fwrite (&student, sizeof(aluno), 1 , editarAluno) != 1 ){ printf("\t OS DADOS DO ALUNO\\A NAO FORAM INTRODUZIDOS \n"); } else { printf("\t OS DADOS DO ALUNO\\A FORAM INTRODUZIDOS COM SUCESSO!! \n"); } } if(fclose(editarAluno) == 0 ){ printf("\t OS DADOS DO ALUNO\A FORAM GUARDADOS COM SUCESSO!! \n"); } else { printf("\t NAO FOI POSSIVEL GUARDAR OD DADOS DO ALUNO\\A!! \n"); } _sleep(3000); opcaoVoltarMenuInicial(); } void eliminarAluno(){ FILE *apagarAluno; aluno student; char eliminar_aluno[40]; int opcao = 0; system("CLS"); printf(""); fflush(stdin); printf(""); printf("\t ELIMINAR FICHEIRO DE UM ALUNO\\A \n\n"); printf(""); printf(" NOME DO ALUNO: "); gets(eliminar_aluno); strcat(eliminar_aluno, ".txt"); if(remove(eliminar_aluno) == 0 ){ printf("\t TODOS OS DADOS DO ALUNO\\A FORAM ELEMINADOS COM SUCESSO!!! \n"); } else { printf("\t ERRO AO APAGAR OS DADOS DO ALUNO\\A !!!!!\n"); } printf("\n"); opcaoVoltarMenuInicial(); } void fimPrograma(){ system("CLS"); printf("OBRIGADO POR CONSULTAR O NOSSO PROGRAMA"); printf("\n"); system("PAUSE"); } Share this post Link to post Share on other sites
HappyHippyHippo 1,165 Report post Posted September 30, 2015 bem ... nem sei por onde começar ... novamente apresentas linhas e linhas de código não indentado e a única coisa que dizes é que dá um erro mágico. devido a isso, a única coisa que estou disposto a fazer é pegar no código e pedir ao computador para ler-lo por mim (compilar-lo) tive que tirar todas as seguintes instruções : _sleep(X) e printf("") que não fazem nada, além de encherem tanto a minha consola de erros que nem conseguia ver todas as mensagens. resultado: src/main.c: In function 'boasVindas': src/main.c:59:1: error: value computed is not used [-Werror=unused-value] -system("CLS"); ^ src/main.c: In function 'vizualizarAluno': src/main.c:183:1: error: implicit declaration of function 'strcat' [-Werror=impl icit-function-declaration] strcat(nameFile, ".txt"); ^ src/main.c:183:1: error: incompatible implicit declaration of built-in function 'strcat' [-Werror] src/main.c:185:8: error: unknown escape sequence: '\A' [-Werror] printf("\n\n\n\t NAO E POSSIVEL ENCONTAR O FICHEIRO DO ALUNO\A... TENTE NOVAM ENTE \n"); ^ src/main.c:188:8: error: unknown escape sequence: '\A' [-Werror] printf("\n\n\n\t O FICHEIRO DO ALUNO\A FOI ENCONTRADO \n"); ^ src/main.c: In function 'adicionarAluno': src/main.c:270:1: error: incompatible implicit declaration of built-in function 'strcat' [-Werror] strcat(nome, student.nome); ^ src/main.c:225:5: error: unused variable 'opcao' [-Werror=unused-variable] int opcao = 0; ^ src/main.c:224:6: error: unused variable 'nameFile' [-Werror=unused-variable] char nameFile[40]; ^ src/main.c: In function 'editarAluno': src/main.c:340:1: error: implicit declaration of function 'strcpy' [-Werror=impl icit-function-declaration] strcpy(student.nome, nome); ^ src/main.c:340:1: error: incompatible implicit declaration of built-in function 'strcpy' [-Werror] src/main.c:346:1: error: incompatible implicit declaration of built-in function 'strcat' [-Werror] strcat(nome, ".txt"); ^ src/main.c:352:8: error: unknown escape sequence: '\A' [-Werror] printf("\n\n\n\t O FICHEIRO DO ALUNO\A FOI ENCONTRADO \n"); ^ src/main.c:388:1: error: format '%s' expects argument of type 'char *', but argu ment 2 has type 'char (*)[100]' [-Werror=format=] scanf("%s", &student.localidade); ^ src/main.c:410:8: error: unknown escape sequence: '\A' [-Werror] printf("\t OS DADOS DO ALUNO\A FORAM GUARDADOS COM SUCESSO!! \n"); ^ src/main.c:327:5: error: unused variable 'opcao' [-Werror=unused-variable] int opcao = 0; ^ src/main.c: In function 'eliminarAluno': src/main.c:441:1: error: incompatible implicit declaration of built-in function 'strcat' [-Werror] strcat(eliminar_aluno, ".txt"); ^ src/main.c:427:5: error: unused variable 'opcao' [-Werror=unused-variable] int opcao = 0; ^ src/main.c:425:7: error: unused variable 'student' [-Werror=unused-variable] aluno student; ^ src/main.c:423:7: error: unused variable 'apagarAluno' [-Werror=unused-variable] FILE *apagarAluno; ^ IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Share this post Link to post Share on other sites