
Pexera
Membros-
Total de itens
6 -
Registro em
-
Última visita
Sobre Pexera

Pexera's Achievements
0
Reputação
-
e mais um erro novo, depois de muito mudar e melhorar o programa... na funcao "insere_novo", em qualuqer tentativa de utilizacao da struct lista o programa trava a execucao.... n sei masi o que fzer =/ esse trabalho tenho que entregar nesta quinta a noite =/ segue os fontes... estrutura.h #ifndef _ESTRUTURA_ #define _ESTRUTURA_H #define TAM_CHAR 50 struct evento{ char nome[TAM_CHAR]; char data[10]; char hora[15]; char local[TAM_CHAR]; struct evento *prox; struct evento *ant; }; typedef struct evento EVENTO; //Funcoes ok void insere_evento(EVENTO **evento,EVENTO **inicio,EVENTO *meses[12]); void insere_evento_arquivo(EVENTO **evento,EVENTO **inicio,EVENTO *meses[12]); void menu(); //exibe o menu de opcoes na tela void mostra_lista(EVENTO *meses[12]); //Imprime a lista na tela int consulta_dado(EVENTO *lista,char nome[TAM_CHAR]); //verifica se um determinado elemento já esta na lista int verifica_vazio(EVENTO* lista);//Verifica se a lista esta vazia.(1 = Vazio - 0 = Com dados) //funcao insere_novo so insere no final ate o momento void insere_novo(EVENTO *meses[12], char nome[TAM_CHAR], char data[10], char hora[15], char local[TAM_CHAR]); //Insere um novo elemento na lista ordenado por data //Fim funcoes ok //fubncoes para implementar void altera_evento(char nome[TAM_CHAR]); //- se altera mês deve trocar a posição na lista de meses void remove_evento(char nome[TAM_CHAR]); void consulta_evento_nome(char nome[TAM_CHAR]); // Saida: datadia, datames, dataano, horário, local); void consulta_evento_data(int data_dia,int data_mes,int data_ano); // S: lista_eventos exibir em ordem cronológica de data void consulta_eventos_mes(int data_mes); // S: lista_eventos); void consulta_eventos(); //S: todos lista_eventos)- em ordem de data ou alfabética pelo nome do evento, ou por outro critério de ordenação à escolha void consulta_eventos_recentes(); //S:cinco últimos eventos manipulados:evento inserido ou alterado (usar fila circular) #endif main.c #include <stdio.h> #include <stdlib.h> #include "estrutura.h" int main(){ EVENTO *evento = NULL; EVENTO *inicio = NULL; EVENTO *meses[12]; int opcao=1,i=0; for(i=0;i<12;i++) meses[i] = NULL; while(opcao !=0){ menu(); scanf("%d",&opcao); //chama_funcao(opcao,&evento,&inicio,&meses); switch(opcao){ case 0: break; case 1: insere_evento(&evento,&inicio,meses); system("pause"); break; case 2: system("pause"); break; case 3: system("pause"); break; case 4: system("pause"); break; case 5: system("pause"); break; case 6: system("pause"); break; case 7: system("pause"); break; case 8: system("pause"); break; default: printf("\nOpcao incorreta!\n"); system("pause"); break; } mostra_lista(meses); //não esta inseridno masi eventos } printf("\n\n"); system("PAUSE"); return 0; } estrutura.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include "estrutura.h" void insere_evento(EVENTO **evento,EVENTO **inicio,EVENTO *meses[12]){ int opcao=1; char nome[TAM_CHAR],data[10],hora[15],local[TAM_CHAR]; printf("\n1 - Arquivo\n2 - Tela\n0 - Retorna\n"); scanf("%d",&opcao); switch(opcao){ case 0: break; case 1: insere_evento_arquivo(&*evento,&*inicio,meses); break; case 2: printf("\nNome do evento: "); scanf("%s",&nome); if((verifica_vazio(*evento)) == 0){ if((consulta_dado(*evento,nome)) == 0){ printf("\nEvento já esta cadastrado!\n"); return; } } printf("\nData: "); scanf("%s",&data); printf("\nHora: "); scanf("%s",&hora); printf("\nLocal: "); scanf("%s",&local); //aquiii //*evento = insere_novo(*evento,meses,nome,data,hora,local); if((verifica_vazio(*inicio) != 0)){ *inicio = *evento; } break; default: printf("\nOpcao incorreta!\n"); break; } } /* -------------------------------------------------------------------------- */ void insere_evento_arquivo(EVENTO **evento,EVENTO **inicio,EVENTO *meses[12]){ FILE *arq; char arqStr[50],linha[TAM_CHAR]; char nome[TAM_CHAR],data[10],hora[15],local[TAM_CHAR]; int i = 0, duplicados = 0,aux=0,mes=0; fflush(stdin); printf("Digite o nome do arquivo:\n"); scanf("%s", arqStr); if ((arq = fopen(arqStr,"r")) == NULL){ fprintf(stderr, "Problema encontrado na abertura do arquivo!\n"); system("pause"); exit(-1); } while(!feof(arq)){ i++; fgets(nome,TAM_CHAR,arq); fgets(data,14,arq); fgets(hora,15,arq); fgets(local,TAM_CHAR,arq); sscanf(data,"%d/%d/%d",&aux,&mes,&aux); /*if((verifica_vazio(meses[mes])) == 0){ if((consulta_dado(meses[mes],nome)) == 0){ duplicados ++; i--; continue; } } */ insere_novo(meses,nome,data,hora,local); } fclose(arq); printf("\nTotal de eventos importados: %d\n", i); printf("\nTotal de eventos duplicados e não importados: %d\n", duplicados); } /* -------------------------------------------------------------------------- */ void menu(){ system("cls"); printf("========================== Agenda Cultural ==========================\n"); printf("\n1 - Insere novo evento"); printf("\n2 - Altera evento"); printf("\n3 - Exclui evento"); printf("\n4 - Consulta evento por nome"); printf("\n5 - Consulta evento por data"); printf("\n6 - Consulta evento por mes"); printf("\n7 - Lista todos os eventos"); printf("\n8 - Lista 5 ultimos eventos. (cadastrados/alterados)"); printf("\n0 - SAIR\n"); } /* -------------------------------------------------------------------------- */ void insere_novo(EVENTO *meses[12], char nome[TAM_CHAR], char data[10], char hora[15], char local[TAM_CHAR]){ EVENTO *novo = (EVENTO*) malloc (sizeof(EVENTO)); EVENTO *lista = NULL; int dia=0,mes=0,ano=0; strcpy(novo->nome,nome); strcpy(novo->data,data); strcpy(novo->hora,hora); strcpy(novo->local,local); sscanf(data,"%d/%d/%d",&dia,&mes,&ano); *lista = *meses[mes]; //move para o ultimo registro da lista printf("\ninsere\n"); if((verifica_vazio(lista)) == 0){ printf("\ndentro\n"); while(lista->prox != NULL){ printf("\ndentro while\n"); lista = lista->prox; printf("\n- SAIR\n"); } printf("\n1 - SAIR\n"); lista->prox = novo; novo->prox = NULL; novo->ant = lista; } else{ novo->prox = NULL; novo->ant = NULL; meses[mes-1] = novo;; } } /* -------------------------------------------------------------------------- */ void mostra_lista(EVENTO *meses[12]){ EVENTO*mostra; int i=0; /*for(i=0;i<12;i++) printf("\nmeses[%d] = %d",i,meses[i]); system("pause");*/ for(i=0;i<12;i++){ //for(mostra = meses[i]; mostra->prox != NULL; mostra = mostra->prox){ mostra = meses[i]; if((verifica_vazio(mostra)) == 0){ printf("\nmeses[%d] = %d",meses[i],mostra->prox); for(mostra = meses[i]; mostra->prox != NULL; mostra = mostra->prox){ printf("\n====================\n"); printf("Evento = %s\n", mostra->nome); printf("Data = %s\n", mostra->data); printf("Hora = %s\n", mostra->hora); printf("Local = %s\n", mostra->local); printf("\n====================\n"); } system("pause"); } else printf("\nNao existem eventos para o mes %d!\n", i+1); } } /* -------------------------------------------------------------------------- */ int verifica_vazio(EVENTO* lista){ return (lista == NULL); } /* -------------------------------------------------------------------------- */ int consulta_dado(EVENTO* lista,char nome[TAM_CHAR]){ EVENTO*mostra; for(mostra = lista; mostra != NULL; mostra = mostra->prox){ if(strcmp(lista->nome,nome) == 0){ return 0; } lista = lista->prox; } return 1; } /* -------------------------------------------------------------------------- */
-
problema novo, estou com problemas com meus ponteiros não consigo fazer com que as structs da main que estao sendo passadas por parametros recebam os valores que são colocados nelas nas funcoes internas. Tanto na funcao insere_evento_arquivo ou na funcao insere_evento_tela estrutura.h #ifndef _ESTRUTURA_H #define _ESTRUTURA_H #define TAM_CHAR 50 struct evento{ char nome[TAM_CHAR]; char data[10]; char hora[15]; char local[TAM_CHAR]; struct evento *prox; struct evento *ant; }; typedef struct evento EVENTO; void insere_evento(EVENTO *evento,EVENTO *inicio); void insere_evento_arquivo(EVENTO *evento,EVENTO *inicio); void insere_evento_tela(EVENTO *evento,EVENTO *inicio,char nome[TAM_CHAR], char data[10], char hora[15], char local[TAM_CHAR]); void altera_evento(char nome[TAM_CHAR]); //- se altera mês deve trocar a posição na lista de meses void remove_evento(char nome[TAM_CHAR]); void consulta_evento_nome(char nome[TAM_CHAR]); // Saida: datadia, datames, dataano, horário, local); void consulta_evento_data(int data_dia,int data_mes,int data_ano); // S: lista_eventos exibir em ordem cronológica de data void consulta_eventos_mes(int data_mes); // S: lista_eventos); void consulta_eventos(); //S: todos lista_eventos)- em ordem de data ou alfabética pelo nome do evento, ou por outro critério de ordenação à escolha void consulta_eventos_recentes(); //S:cinco últimos eventos manipulados:evento inserido ou alterado (usar fila circular) void menu(); void chama_funcao(int opcao,EVENTO *evento,EVENTO *inicio); #endif main.c #include <stdio.h> #include <stdlib.h> #include "estrutura.h" int main(){ EVENTO *evento; EVENTO *inicio; int opcao = 1; inicio=NULL; while(opcao !=0){ menu(); scanf("%d",&opcao); chama_funcao(opcao,evento,inicio); } printf("\n\n"); system("PAUSE"); return 0; } estrutura.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include "estrutura.h" void insere_evento(EVENTO *evento,EVENTO *inicio){ int opcao=1; char nome[TAM_CHAR],data[10],hora[15],local[TAM_CHAR]; printf("\n1 - Arquivo\n2 - Tela\n0 - Retorna\n"); scanf("%d",&opcao); switch(opcao){ case 0: break; case 1: insere_evento_arquivo(evento,inicio); break; case 2: printf("\nNome do evento: "); scanf("%s",&nome); if(inicio != NULL){ printf("\ninicio não nulo: "); evento = inicio; while(evento->prox != NULL){ if(strcmp(evento->nome,nome) == 0){ printf("\nEvento já esta cadastrado para o dia %s ",evento->data); return; } evento = evento->prox; } } printf("\nData: "); scanf("%s",&data); printf("\nHora: "); scanf("%s",&hora); printf("\nLocal: "); scanf("%s",&local); insere_evento_tela(evento,inicio,nome,data,hora,local); break; default: printf("\nOpcao incorreta!\n"); break; } } /* -------------------------------------------------------------------------- */ void insere_evento_arquivo(EVENTO *evento,EVENTO *inicio){ FILE *arq; char arqStr[50],linha[TAM_CHAR]; int i = 0, duplicados = 0; EVENTO *atual = inicio; EVENTO *aux = NULL; fflush(stdin); printf("Digite o nome do arquivo:\n"); //scanf("%s", arqStr); if ((arq = fopen("agenda.txt" /*arqStr*/,"r")) == NULL){ fprintf(stderr, "Problema encontrado na abertura do arquivo!"); exit(-1); } while(!feof(arq)){ evento=(EVENTO*)malloc(sizeof(EVENTO)); evento->ant=NULL; evento->prox=NULL; atual = inicio; if(inicio == NULL){ i++; fgets(evento->nome,TAM_CHAR,arq); fgets(evento->data,14,arq); fgets(evento->hora,15,arq); fgets(evento->local,TAM_CHAR,arq); inicio = evento; } else{ //move para o ultimo registro da lista while(atual->prox != NULL){ atual = atual->prox; } i++; fgets(evento->nome,TAM_CHAR,arq); fgets(evento->data,14,arq); fgets(evento->hora,15,arq); fgets(evento->local,TAM_CHAR,arq); evento->ant = atual; atual->prox = evento; } } fclose(arq); printf("\nTotal de eventos importados: %d\n", i); printf("\nTotal de eventos duplicados e não importados: %d\n", duplicados); system("pause"); return; } /* -------------------------------------------------------------------------- */ void insere_evento_tela(EVENTO *evento,EVENTO *inicio,char nome[TAM_CHAR], char data[10], char hora[15], char local[TAM_CHAR]){ EVENTO *atual = inicio; evento=(EVENTO*)malloc(sizeof(EVENTO)); evento->ant=NULL; evento->prox=NULL; atual = inicio; if(inicio == NULL){ strcpy(evento->nome, nome); strcpy(evento->data, data); strcpy(evento->hora, hora); strcpy(evento->local, local); printf("\ninicio inicializando"); system("pause"); *inicio = *evento; printf("\ninicio inicializando"); system("pause"); } else{ //move para o ultimo registro da lista while(atual->prox != NULL){ atual = atual->prox; } strcpy(evento->nome, nome); strcpy(evento->data, data); strcpy(evento->hora, hora); strcpy(evento->local, local); evento->ant = atual; atual->prox = evento; printf("\nlinha : %s", evento->nome); printf("\nlinha : %s", evento->data); printf("\nlinha : %s", evento->hora); printf("\nlinha : %s", evento->local); } printf("\nTotal de eventos duplicados e não importados: %d\n"); return; } /* -------------------------------------------------------------------------- */ void menu(){ system("cls"); printf("========================== Agenda Cultural ==========================\n"); printf("\n1 - Insere novo evento"); printf("\n2 - Altera evento"); printf("\n3 - Exclui evento"); printf("\n4 - Consulta evento por nome"); printf("\n5 - Consulta evento por data"); printf("\n6 - Consulta evento por mes"); printf("\n7 - Lista todos os eventos"); printf("\n8 - Lista 5 ultimos eventos. (cadastrados/alterados)"); printf("\n0 - SAIR\n"); } /* -------------------------------------------------------------------------- */ void chama_funcao(int opcao,EVENTO *evento,EVENTO *inicio){ switch(opcao){ case 0: break; case 1: insere_evento(evento,inicio); break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; default: printf("\nOpcao incorreta!\n"); system("pause"); break; } } /* -------------------------------------------------------------------------- */
-
estranhamente, declarando a data como 10 e lendo como 14 ele funciona de forma correta, enfim não tenho muito tempo para estudar melhor esta cituacao pois o trabalho é para quinta feira, então apos eu acaba-lo vou verificar essa situacao melhor e se encontrar uma explicacao certa eu posto aki. quanto ao fgets o que sei é: A função FGETS lê uma linha inteira de uma vez. Exemplo: result = fgets(Linha, 100, arq); // o 'fgets' lê até 99 caracteres ou até o '\n' Se a função for executada com sucesso, fgets retorna o endereço da string lida, caso contrário retorna NULL.
-
então ai é que esta se eu faco isso o resultado é: Noite na Musica Latina 05/01/201 0 21h e se eu altero a struct da forma abaixo fica da mesma forma que a do post anterior =/ struct evento{ char nome[TAM_CHAR]; char data[TAM_CHAR]; char hora[TAM_CHAR]; char local[TAM_CHAR]; struct evento *prox; struct evento *ant; };
-
vlwwssssss muito obrigado mesmo, já tava pirando com isso, asuahsuahs que erro tosco meu, mas enfim é akela velha coisa não é?, uma opniao de fora sempre acha essas coisas..^^ muito obrigado mesmo. mais uma duvida agora heheh esta importando errado os dados, é algo com o tamanho da leitura eu acho mas n tenho certeza, Deveria importar: Noite na Musica Latina 05/01/2010 21h Casa da Cultura mas importa Noite na Musica Latina 05/01/201021h 21h Casa da Cultura
-
Olá pessoal, estou implementando um trablaho de estrutura de dados e primeiramente gostaria de dizer que não busco o trabalho pronto, então vou postar somente a parte especifica que esta com problema. Seguinte, o progra cujos codigos vou colar abaixo, deve importar atraves da funcao "insere_evento_arquivo", dados sobre eventos registras em um arquivo texto agenda.txt, porem no laco de leitura e alocacao de memoria o programa simplesmente fecha e não sei mais como corrigir o erro. Segue os fontes: Main.c (não consegui por em CODEBOX) Estrutura.h Estrutura.c