-
-
Save maopd265/c15f01b0ad6c53eca36679549672b64e to your computer and use it in GitHub Desktop.
CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <time.h> | |
#include <locale.h> | |
#include<errno.h> | |
#include<time.h> | |
#define N 10000 | |
#define M 800 | |
#define Z 300 | |
#define P 1000 | |
#define A 10 | |
#define Q 100 | |
typedef struct filme{ | |
char nome[P]; | |
char ano[14]; | |
struct duplaAt *listaAtores; | |
struct duplaDir *listaDiretores; | |
struct filme *next; | |
struct filme *prev; | |
}filme; | |
typedef struct Ator{ | |
char nome[P]; | |
struct duplaFilm *listaFilmes; | |
struct Ator *next; | |
struct Ator *prev; | |
}ator; | |
typedef struct diretor{ | |
char nome[P]; | |
struct duplaFilm *listaFilmes; | |
struct diretor *next; | |
struct diretor *prev; | |
}diretor; | |
typedef struct duplaAt{ | |
struct Ator *at; | |
struct duplaAt *next; | |
struct duplaAt *prev; | |
}duplaAt; | |
typedef struct duplaDir{ | |
struct diretor *dir; | |
struct duplaDir *next; | |
struct duplaDir *prev; | |
}duplaDir; | |
typedef struct duplaFilm{ | |
struct filme *fil; | |
struct duplaFilm *next; | |
struct duplaFilm *prev; | |
}duplaFilm; | |
typedef struct Lista { | |
char *data; | |
struct Lista *next; | |
}Lista; | |
void insereAtor(struct Ator ** inicioAt, struct Ator ** fimAt, char nome[Q], filme * filme, ator ** at) | |
{ | |
int i, comparacao; | |
struct Ator * verifica= *inicioAt; | |
duplaFilm *nodo=(duplaFilm *) malloc(sizeof(duplaFilm)); | |
nodo->fil=filme; | |
for(i=0;nome[i]!='\0'; i++) | |
{ | |
nome[i]= toupper(nome[i]); | |
if(nome[i]=='Ã'||nome[i]=='Á'||nome[i]=='Ä'||nome[i]=='À'||nome[i]=='Â') | |
{ | |
nome[i]='A'; | |
} | |
if(nome[i]=='É'||nome[i]=='È'||nome[i]=='Ë'||nome[i]=='Ê') | |
{ | |
nome[i]='E'; | |
} | |
if(nome[i]=='Í'||nome[i]=='Ì'||nome[i]=='Î'||nome[i]=='Ï') | |
{ | |
nome[i]='I'; | |
} | |
if(nome[i]=='Õ'||nome[i]=='Ó'||nome[i]=='Ö'||nome[i]=='Ò'||nome[i]=='Ô') | |
{ | |
nome[i]='O'; | |
} | |
if(nome[i]=='Ú'||nome[i]=='Ù'||nome[i]=='Ü'||nome[i]=='Û') | |
{ | |
nome[i]='U'; | |
} | |
} | |
nome[i]='\0'; | |
while(verifica!=NULL) | |
{ | |
comparacao=strcmp(nome, verifica->nome); | |
if(comparacao== 0) | |
{ | |
if(verifica->listaFilmes==NULL) | |
{ | |
verifica->listaFilmes=nodo; | |
nodo->next=NULL; | |
} | |
else | |
{ | |
duplaFilm * aux4=verifica->listaFilmes; | |
while((aux4->next)!=NULL) | |
{ | |
aux4=aux4->next; | |
} | |
aux4->next=nodo; | |
nodo->next=NULL; | |
} | |
*at=verifica; | |
return; | |
} | |
verifica=verifica->next; | |
} | |
ator *novo=(ator *) malloc(sizeof(ator)); | |
novo->prev=NULL; | |
novo->next=NULL; | |
novo->listaFilmes=NULL; | |
strcpy(novo->nome,nome); | |
if(novo->listaFilmes==NULL) | |
{ | |
novo->listaFilmes=nodo; | |
nodo->next=NULL; | |
} | |
else | |
{ | |
duplaFilm * aux3=novo->listaFilmes; | |
while((aux3->next)!=NULL) | |
{ | |
aux3=aux3->next; | |
} | |
aux3->next=nodo; | |
nodo->next=NULL; | |
} | |
*at=novo; | |
ator * aux=*inicioAt; | |
ator * aux1=*inicioAt; | |
ator * aux2=*fimAt; | |
if(*inicioAt==NULL) | |
{ | |
*inicioAt=novo; | |
*fimAt=novo; | |
novo->next=NULL; | |
novo->prev =NULL; | |
} | |
else | |
{ | |
comparacao=strcmp(nome, aux2->nome); | |
if(comparacao>0)// novo > fim | |
{ | |
aux2->next=novo; | |
novo->next=NULL; | |
novo->prev=*fimAt; | |
*fimAt=novo; | |
} | |
else | |
{ | |
comparacao=strcmp(nome,aux1->nome); | |
if(comparacao<0)// novo < inicio | |
{ | |
novo->next=*inicioAt; | |
novo->prev=NULL; | |
aux1->prev=novo; | |
*inicioAt=novo; | |
} | |
else | |
{ | |
while(strcmp(nome,aux->next->nome)>=1)// novo > aux->next | |
{ | |
if(aux->next->nome!=NULL) | |
{ | |
aux=aux->next; | |
} | |
if(aux->next==NULL) | |
break; | |
} | |
novo->next=aux->next; | |
aux->next=novo; | |
novo->prev=aux; | |
novo->next->prev=novo; | |
} | |
} | |
} | |
} | |
void excluirPrincipal(char auxInsert[P], filme ** inicioFilmes, filme ** fimFilmes) | |
{ | |
struct filme *writeFilm=*inicioFilmes; | |
while(writeFilm!=NULL) | |
{ | |
if(strcmp(auxInsert,writeFilm->nome)==0) | |
{ | |
if(writeFilm->prev==NULL && writeFilm->next==NULL) | |
{ | |
*inicioFilmes=NULL; | |
*fimFilmes=NULL; | |
free(writeFilm); | |
} | |
if(writeFilm->prev==NULL && writeFilm->next!=NULL) | |
{ | |
//PRIMEIRO | |
writeFilm->next->prev=NULL; | |
*inicioFilmes=writeFilm->next; | |
free(writeFilm); | |
} | |
if(writeFilm->prev!=NULL && writeFilm->next==NULL) | |
{ | |
writeFilm->prev->next=NULL; | |
*fimFilmes=writeFilm->prev; | |
free(writeFilm); | |
} | |
if(writeFilm->prev!=NULL && writeFilm->next!=NULL) | |
{ | |
writeFilm->prev->next=writeFilm->next; | |
writeFilm->next->prev=writeFilm->prev; | |
free(writeFilm); | |
} | |
} | |
writeFilm=writeFilm->next; | |
} | |
} | |
void excluirAtRef(char auxInsert[P], struct Ator ** inicioAtores,struct Ator ** fimAtores) | |
{ | |
struct Ator * atorHead=*inicioAtores; | |
struct duplaFilm *refFilme; | |
int band; | |
while(atorHead!=NULL) | |
{ | |
band=1; | |
refFilme=atorHead->listaFilmes; | |
while(refFilme!=NULL) | |
{ | |
if(strcmp(refFilme->fil->nome,auxInsert)==0) | |
{ | |
//flag | |
if(refFilme->prev==NULL && refFilme->next==NULL) | |
{ | |
free(refFilme); | |
band=0; | |
} | |
if(refFilme->prev==NULL && refFilme->next!=NULL) | |
{ | |
refFilme->next->prev=NULL; | |
free(refFilme); | |
} | |
if(refFilme->prev!=NULL && refFilme->next!=NULL) | |
{ | |
refFilme->prev->next = refFilme->next; | |
refFilme->next->prev = refFilme->prev; | |
free(refFilme); | |
} | |
if(refFilme->prev!=NULL && refFilme->next==NULL) | |
{ | |
refFilme->prev->next = NULL; | |
// refFilme = refFilme->prev; | |
free(refFilme); | |
} | |
} | |
refFilme=refFilme->next; | |
} | |
if(band==0) | |
{ | |
if(atorHead->prev==NULL && atorHead->next==NULL) | |
{ | |
*inicioAtores=NULL; | |
*fimAtores=NULL; | |
free(atorHead); | |
} | |
if(atorHead->prev==NULL && atorHead->next!=NULL) | |
{ | |
atorHead->next->prev = NULL; | |
*inicioAtores = atorHead->next; | |
free(atorHead); | |
} | |
if(atorHead->prev!=NULL && atorHead->next!=NULL) | |
{ | |
atorHead->prev->next = atorHead->next; | |
atorHead->next->prev = atorHead->prev; | |
free(atorHead); | |
} | |
if(atorHead->prev!=NULL && atorHead->next==NULL) | |
{ | |
atorHead->prev->next = NULL; | |
*fimAtores= atorHead->prev; | |
free(atorHead); | |
} | |
} | |
atorHead=atorHead->next; | |
} | |
} | |
void insertAll(filme ** filmeInicio, struct Ator ** atorInicio, filme ** fim,struct Ator ** tailAt, char titulo[M], char ano[14], char atores[M], char diretores[P]) | |
{ | |
int i, comparacao, flag=0,j=0, j1=0; | |
char nomeAtor[Q]; | |
for(i=0;titulo[i]!='\0'; i++) | |
{ | |
titulo[i]= toupper(titulo[i]); | |
if(titulo[i]=='Ã'||titulo[i]=='Á'||titulo[i]=='Ä'||titulo[i]=='À'||titulo[i]=='Â') | |
{ | |
titulo[i]='A'; | |
} | |
if(titulo[i]=='É'||titulo[i]=='È'||titulo[i]=='Ë'||titulo[i]=='Ê') | |
{ | |
titulo[i]='E'; | |
} | |
if(titulo[i]=='Í'||titulo[i]=='Ì'||titulo[i]=='Î'||titulo[i]=='Ï') | |
{ | |
titulo[i]='I'; | |
} | |
if(titulo[i]=='Õ'||titulo[i]=='Ó'||titulo[i]=='Ö'||titulo[i]=='Ò'||titulo[i]=='Ô') | |
{ | |
titulo[i]='O'; | |
} | |
if(titulo[i]=='Ú'||titulo[i]=='Ù'||titulo[i]=='Ü'||titulo[i]=='Û') | |
{ | |
titulo[i]='U'; | |
} | |
} | |
titulo[i]='\0'; | |
filme * verifica=*filmeInicio; | |
while(verifica!=NULL) | |
{ | |
comparacao=strcmp(titulo, verifica->nome); | |
if(comparacao== 0) | |
{ | |
return; | |
} | |
verifica=verifica->next; | |
} | |
filme *novo=(filme *) malloc(sizeof(filme)); | |
novo->prev=NULL; | |
novo->next=NULL; | |
novo->listaAtores=NULL; | |
strcpy(novo->nome,titulo); | |
strcpy(novo->ano,ano); | |
struct Ator * at,* inicioAtor, *fimAtor; | |
inicioAtor=*atorInicio; | |
fimAtor=*tailAt; | |
filme * aux=*filmeInicio; | |
filme * aux1=*filmeInicio; | |
filme * aux2=*fim; | |
for(i=0;atores[i] != '\0' && atores[i] !=0 && i<strlen(atores) && atores[i] !=A;i++) | |
{ | |
nomeAtor[0]= '\0'; | |
while(atores[j]!=',' && atores[j]!=0 && atores[j] != '\0' && atores[j] != '\n') | |
{ | |
nomeAtor[j-j1]=atores[j]; | |
j++; | |
} | |
nomeAtor[j-j1]= '\0'; | |
if(atores[j]!='\0') | |
j++; | |
j1=j; | |
duplaAt *nodo=(duplaAt *) malloc(sizeof(duplaAt)); | |
if(novo->listaAtores==NULL) | |
{ | |
novo->listaAtores=nodo; | |
insereAtor(&inicioAtor, &fimAtor, nomeAtor, novo, &at); | |
nodo->at=at; | |
nodo->next=NULL; | |
} | |
else | |
{ | |
duplaAt * aux3=novo->listaAtores; | |
while((aux3->next)!=NULL) | |
{ | |
aux3=aux3->next; | |
} | |
aux3->next=nodo; | |
insereAtor(&inicioAtor, &fimAtor, nomeAtor, novo, &at); | |
nodo->at=at; | |
nodo->next=NULL; | |
} | |
i=j; | |
} | |
if(*filmeInicio==NULL) | |
{ | |
*filmeInicio=novo; | |
*fim=novo; | |
novo->next=NULL; | |
novo->prev =NULL; | |
} | |
else | |
{ | |
comparacao=strcmp(titulo, aux2->nome); | |
if(comparacao>0) | |
{ | |
aux2->next=novo; | |
novo->next=NULL; | |
novo->prev=*fim; | |
*fim=novo; | |
} | |
else | |
{ | |
comparacao=strcmp(titulo,aux1->nome); | |
if(comparacao<0) | |
{ | |
novo->next=*filmeInicio; | |
novo->prev=NULL; | |
aux1->prev=novo; | |
*filmeInicio=novo; | |
flag=1; | |
} | |
else | |
{ | |
while(strcmp(titulo,aux->next->nome)>=1) | |
{ | |
aux=aux->next; | |
flag=1; | |
} | |
novo->next=aux->next; | |
aux->next=novo; | |
novo->prev=aux; | |
novo->next->prev=novo; | |
} | |
} | |
} | |
*atorInicio=inicioAtor; | |
*tailAt=fimAtor; | |
} | |
void desmembrar(filme **inicioFilmes, filme **fimFilmes, ator **inicioAtores, ator **fimAtores) | |
{ | |
FILE *arq = fopen("resumo.txt","rt"); | |
char linha[P], aux[P],titulo[M],ano[A], diretores[M], atores[M]; | |
int i=0, j=0, k=0, d=0, a=0; | |
filme * inicioFilme, *fimFilme; | |
inicioFilme=*inicioFilmes; | |
fimFilme=*fimFilmes; | |
ator * inicioAtor, *fimAtor; | |
inicioAtor=*inicioAtores; | |
fimAtor=*fimAtores; | |
if(arq == NULL){ | |
printf("Erro, nao foi possivel abrir o arquivo de desmembramento arq\n"); | |
switch (errno) { | |
case EPERM: | |
printf("Operação não permitida"); | |
break; | |
case ENOENT: | |
printf("Arquivo dados.txt não encontrado"); | |
break; | |
case EACCES: | |
printf("Você não tem permissões suficientes"); | |
break; | |
default: | |
printf("Algo sinistro está acontecendo aqui..."); | |
break; | |
} | |
} | |
else | |
{ | |
while((fgets(aux, sizeof(aux), arq))!=NULL) | |
{ | |
i=0, j=0, k=0, d=0, a=0; | |
//Mudar essas variaveis | |
linha[0]='\0'; | |
titulo[0]='\0'; | |
ano[0]='\0'; | |
diretores[0]='\0'; | |
atores[0]='\0'; | |
while(aux[i]!='\0') | |
{ | |
linha[i]=aux[i]; | |
i++; | |
} | |
linha[i]='\0'; | |
while(linha[j]!=',') | |
{ | |
titulo[j]=linha[j]; | |
j++; | |
} | |
titulo[j]='\0'; | |
j++; | |
if(linha[j]==',') | |
{ | |
ano[0]='\0'; | |
} | |
else | |
{ | |
while(linha[j]!=',') | |
{ | |
ano[k]=linha[j]; | |
j++; | |
k++; | |
} | |
ano[k]='\0'; | |
} | |
j++; | |
if(linha[j]==',') | |
{ | |
diretores[0]='\0'; | |
} | |
else | |
{ | |
while(linha[j]!=',' && linha[j]!=linha[i]) | |
{ | |
diretores[d]=linha[j]; | |
j++; | |
d++; | |
} | |
j++; | |
while((linha[j]=='d' || linha[j]=='D') && (linha[j+1]=='i' || linha[j+1]=='I') && (linha[j+2]=='r' || linha[j+2]=='R') && linha[j+3]==':') | |
{ | |
diretores[d]=','; | |
j=j+4; | |
d++; | |
while(linha[j]!=',' && linha[j]!=linha[i]) | |
{ | |
diretores[d]=linha[j]; | |
j++; | |
d++; | |
} | |
j++; | |
} | |
diretores[d]='\0'; | |
} | |
if(linha[j]!=linha[i] && linha[j-1]!=linha[i]) | |
{ | |
while(linha[j]!=linha[i]) | |
{ | |
while(linha[j]!=',' && linha[j]!=linha[i]) | |
{ | |
atores[a]=linha[j]; | |
a++; | |
j++; | |
if(linha[j]=='=') | |
{ | |
while(linha[j]!=',' && linha[j]!='\0') | |
j++; | |
break; | |
} | |
} | |
if(linha[j]==',') | |
{ | |
atores[a]=','; | |
a++; | |
j++; | |
} | |
else | |
atores[a]='\0'; | |
} | |
} | |
else | |
atores[a]='\0'; | |
insertAll(&inicioFilme, &inicioAtor, &fimFilme, &fimAtor, titulo, ano, atores, diretores); | |
} | |
} | |
*inicioFilmes=inicioFilme; | |
*fimFilmes=fimFilme; | |
*inicioAtores=inicioAtor; | |
*fimAtores=fimAtor; | |
} | |
void Menu() | |
{ | |
printf("\n\nBem vindo ao programa de texto\n"); | |
printf("------------------------------------------------------------------------------"); | |
printf("\n1 - LISTAR TODOS OS ATORES EM ORDEM |"); | |
printf("\n2 - LISTAR FILMES DE UM ATOR EM ORDEM CRONOLOGICA |"); | |
printf("\n3 - LISTAR TODOS OS FILMES EM ORDEM |"); | |
printf("\n4 - INSERIR FILME |"); | |
printf("\n5- REMOVER FILME |"); | |
printf("\n6- LIMPAR A TELA |"); | |
printf("\n0 - SAIR DO PROGRAMA |"); | |
printf("\n------------------------------------------------------------------------------"); | |
} | |
struct Lista *InsertDec(struct Lista *head, const char *data) { | |
struct Lista *newp; | |
struct Lista *tmp; | |
char *new_data; | |
/* aloca o novo item */ | |
newp = ((struct Lista*)malloc(sizeof(struct Lista))); | |
new_data = strdup(data); | |
//strdup aloca memória na pilha. | |
if (newp == NULL || new_data == NULL) { | |
fprintf(stderr, "out of memory"); | |
return NULL; | |
} | |
newp->data = new_data; | |
newp->next = NULL; | |
/* verificar o elemento deve ser inserido na cabeça*/ | |
if (head == NULL || strcmp(new_data, head->data) < 0) { | |
newp->next = head; | |
head = newp; | |
} else { | |
/* caso contrário, encontre o ponto de inserção */ | |
tmp = head; | |
while (tmp->next && strcmp(new_data, tmp->next->data) <= 0) { | |
tmp = tmp->next; | |
} | |
newp->next = tmp->next; | |
tmp->next = newp; | |
} | |
return head; | |
} | |
void escrever(struct Lista * film,struct Lista * filmes) | |
{ | |
int i=1; | |
for (film = filmes; film != NULL; film = film->next) { | |
printf("\n Filme %d:%s",i, film->data); | |
i++; | |
} | |
} | |
int main() | |
{ | |
system("color a"); | |
setlocale(LC_ALL,""); | |
printf ("SEU PROGRAMA FOI CONFIGURADO PARA: %s\n", setlocale(LC_ALL,NULL) ); | |
//setlocale permite acentos | |
printf("\nDIA ATUAL:"); | |
system ( "date /t" ); | |
printf("\nHORA INICIAL:"); | |
system ("time /t"); | |
struct Ator *escrita,*escritaDec; | |
struct duplaAt *atorM = NULL; | |
struct duplaFilm *refFilme=NULL,*refFilme2; | |
FILE* arq3; | |
int option, i,cont,zx,op6; | |
int band=0; | |
struct duplaFilm *atual = NULL, *aux_ref = NULL,*tprev= NULL,*tst; | |
filme *aux_filme; | |
filme * inicioFilmes=NULL,* fimFilmes=NULL,* writeFilm,*auxFilm; | |
struct Ator * inicioAtores=NULL,* fimAtores=NULL,*atormovie,*atorHead,*atorTail; | |
struct Lista *filmes=NULL,*film,*filmes2=NULL,*film2; | |
int desc; | |
char nomeAtor[Q], nomeFilme[M], ano[A], diretores[M], atores[M], ator[Q], filme[M], aux[M],linha[P]; | |
char auxInsert[Z]; | |
int aq; | |
desmembrar(&inicioFilmes, &fimFilmes, &inicioAtores, &fimAtores); | |
//AQUIIIIIIIIII INICIO ATORES | |
atorHead=inicioAtores; | |
//atores inicio INIDICADO LEMBRAR | |
do{ | |
printf("\nPARA CARREGAR O ARQUIVO DIGITE 1:"); | |
scanf("%d",&zx); | |
}while(zx!=1); | |
if(zx==1) | |
{ | |
system("cls"); | |
arq3 = fopen("resumo.txt", "r"); | |
if (arq3 == NULL) { | |
printf("Ocorreu um erro no arquivo 1!"); | |
switch (errno) { | |
case EPERM: | |
printf("Operação não permitida"); | |
break; | |
case ENOENT: | |
printf("Arquivo dados.txt não encontrado"); | |
break; | |
case EACCES: | |
printf("Você não tem permissões suficientes"); | |
break; | |
default: | |
printf("Algo sinistro está acontecendo aqui..."); | |
break; | |
} | |
return 1; | |
} | |
} | |
while (fgets(linha, sizeof linha, arq3)) { | |
char *p1 = strtok(linha, ","); | |
filmes2 = InsertDec(filmes2, p1); | |
//char *p = strtok(linha, ","); | |
//filmes2 = InsertOrd(filmes, p); | |
//LISTA DE FILMES INVERTIDAS CARREGADAS | |
} | |
fclose(arq3); | |
do{ | |
Menu(); | |
printf("\n"); | |
scanf("%d",&option); | |
switch (option) | |
{ | |
case 1 : | |
printf("\n Voce gostaria de listar em ordem alfabetica ou alfabetica reversa (0/1) :"); | |
scanf("%d",&op6); | |
if(op6==0) | |
{ | |
escrita=inicioAtores; | |
cont=1; | |
while(escrita!=NULL) | |
{ | |
if(escrita->nome[0]!=0) | |
printf("\nAtor %d :%s\n",cont, escrita->nome); | |
cont++; | |
escrita=escrita->next; | |
} | |
} | |
else if(op6==1) | |
{ | |
escritaDec=fimAtores; | |
cont=1; | |
while(escritaDec!=NULL) | |
{ | |
if(escritaDec->nome[0]!=0) | |
printf("\nAtor %d :%s\n",cont, escritaDec->nome); | |
escritaDec=escritaDec->prev; | |
cont++; | |
} | |
} | |
else | |
{ | |
printf("Opção não existe!!\n"); | |
} | |
break; | |
case 2 : | |
desc=0; | |
printf("\n--LISTAR FILMES DE UM ATOR EM ORDEM CRONOLÓGICA--\n"); | |
printf("\nDigite o nome do ator:"); | |
int aux2; | |
setbuf(stdin, NULL); | |
//fgets(nomeAtor, P, stdin); | |
scanf("%[^\n]s", nomeAtor); | |
if(nomeAtor==NULL) | |
{ | |
printf("ATOR NÃO EXISTE!"); | |
} | |
for(i=0;nomeAtor[i]!='\0'; i++) | |
{ | |
nomeAtor[i]= toupper(nomeAtor[i]); | |
if(nomeAtor[i]=='Ã'||nomeAtor[i]=='Á'||nomeAtor[i]=='Ä'||nomeAtor[i]=='À'||nomeAtor[i]=='Â') | |
{ | |
nomeAtor[i]='A'; | |
} | |
if(nomeAtor[i]=='É'||nomeAtor[i]=='È'||nomeAtor[i]=='Ë'||nomeAtor[i]=='Ê') | |
{ | |
nomeAtor[i]='E'; | |
} | |
if(nomeAtor[i]=='Í'||nomeAtor[i]=='Ì'||nomeAtor[i]=='Î'||nomeAtor[i]=='Ï') | |
{ | |
nomeAtor[i]='I'; | |
} | |
if(nomeAtor[i]=='Õ'||nomeAtor[i]=='Ó'||nomeAtor[i]=='Ö'||nomeAtor[i]=='Ò'||nomeAtor[i]=='Ô') | |
{ | |
nomeAtor[i]='O'; | |
} | |
if(nomeAtor[i]=='Ú'||nomeAtor[i]=='Ù'||nomeAtor[i]=='Ü'||nomeAtor[i]=='Û') | |
{ | |
nomeAtor[i]='U'; | |
} | |
} | |
nomeAtor[i]='\0'; | |
atormovie=inicioAtores; | |
// printf("nome:%s \natormovie:%s \n",nomeAtor,atormovie->nome); | |
if(atormovie==NULL) | |
{ | |
printf("\nA LISTA ESTÁ VAZIA!!!"); | |
}else{ | |
printf("\n---------------------------------------------------------------------------\n"); | |
while(atormovie!=NULL) | |
{ | |
if(strcmp(atormovie->nome,nomeAtor)==0) | |
{ | |
desc=1; | |
printf("Ator encontrado na lista!"); | |
//system("pause"); | |
do{ | |
band=1; | |
tprev=atormovie->listaFilmes; | |
atual=tprev->next; | |
while(atual != NULL){ | |
if(strcmp(tprev->fil->ano,atual->fil->ano) > 0){ | |
aux_filme = tprev->fil; | |
tprev->fil = atual->fil; | |
atual->fil = (aux_filme); | |
band=0; | |
} | |
tprev=atual; | |
atual=atual->next; | |
} | |
}while(band==0); | |
printf("\n--------------------\n"); | |
printf("\nATOR:%s\n",nomeAtor); | |
tst=atormovie->listaFilmes; | |
while(tst!=NULL) | |
{ | |
printf("\n\nFILME : %s \n ANO DE PUBLICAÇÃO: %s",tst->fil->nome,tst->fil->ano); | |
tst=tst->next; | |
} | |
} | |
atormovie=atormovie->next; | |
} | |
if(desc!=1) | |
{ | |
printf("\nAtor não encontrado!\n"); | |
} | |
} | |
break; | |
case 3 : | |
printf("\n Voce gostaria de listar em ordem alfabetica ou alfabetica reversa (0/1) :"); | |
int op3; | |
scanf("%d",&op3); | |
if(op3==0){ | |
//necessario conversao | |
writeFilm=inicioFilmes; | |
int wre=1; | |
while(writeFilm!=NULL) | |
{ | |
printf("\nFilme %d: %s",wre,writeFilm->nome); | |
writeFilm=writeFilm->next; | |
wre++; | |
} | |
}else if(op3==1){ | |
writeFilm=fimFilmes; | |
int wre2=1; | |
while(writeFilm!=NULL) | |
{ | |
printf("\nFilme %d: %s",wre2,writeFilm->nome); | |
writeFilm=writeFilm->prev; | |
wre2++; | |
} | |
//normal aparece tudo ok | |
// escrever(film2,filmes2); | |
}else{ | |
printf("\nOpção incorreta, tente novamente!"); | |
} | |
break; | |
case 4: | |
printf("\nVOCE ESCOLHEU A OPÇÃO INSERIR \n "); | |
int sn; | |
printf("\n Digite o nome do filme que voce quer adicionar:"); | |
setbuf(stdin, NULL); | |
//pegar os espaços | |
scanf("%[^\n]s",auxInsert); | |
for(i=0;auxInsert[i]!='\0'; i++) | |
{ | |
auxInsert[i]= toupper(auxInsert[i]); | |
if(auxInsert[i]=='Ã'||auxInsert[i]=='Á'||auxInsert[i]=='Ä'||auxInsert[i]=='À'||auxInsert[i]=='Â') | |
{ | |
auxInsert[i]='A'; | |
} | |
if(auxInsert[i]=='É'||auxInsert[i]=='È'||auxInsert[i]=='Ë'||auxInsert[i]=='Ê') | |
{ | |
auxInsert[i]='E'; | |
} | |
if(auxInsert[i]=='Í'||auxInsert[i]=='Ì'||auxInsert[i]=='Î'||auxInsert[i]=='Ï') | |
{ | |
auxInsert[i]='I'; | |
} | |
if(auxInsert[i]=='Õ'||auxInsert[i]=='Ó'||auxInsert[i]=='Ö'||auxInsert[i]=='Ò'||auxInsert[i]=='Ô') | |
{ | |
auxInsert[i]='O'; | |
} | |
if(auxInsert[i]=='Ú'||auxInsert[i]=='Ù'||auxInsert[i]=='Ü'||auxInsert[i]=='Û') | |
{ | |
auxInsert[i]='U'; | |
} | |
} | |
auxInsert[i]='\0'; | |
writeFilm=inicioFilmes; | |
while(writeFilm!=NULL) | |
{ | |
if(strcmp(auxInsert,writeFilm->nome)==0){ | |
sn=1; | |
} | |
writeFilm=writeFilm->next; | |
} | |
if(sn==1) | |
{ | |
printf("\nEsse filme já existe na lista!\n"); | |
} | |
else | |
{ | |
printf("\n -Nome de filme válido, por favor insira as demais informações necessárias-\n"); | |
printf("\nANO: "); | |
scanf("%s",ano); | |
printf("\nDIRETOR (ES): "); | |
setbuf(stdin, NULL); | |
//pegar os espaços | |
scanf("%[^\n]s",diretores); | |
for(i=0;diretores[i]!='\0'; i++) | |
{ | |
diretores[i]= toupper(diretores[i]); | |
if(diretores[i]=='Ã'||diretores[i]=='Á'||diretores[i]=='Ä'||diretores[i]=='À'||diretores[i]=='Â') | |
{ | |
diretores[i]='A'; | |
} | |
if(diretores[i]=='É'||diretores[i]=='È'||diretores[i]=='Ë'||diretores[i]=='Ê') | |
{ | |
diretores[i]='E'; | |
} | |
if(diretores[i]=='Í'||diretores[i]=='Ì'||diretores[i]=='Î'||diretores[i]=='Ï') | |
{ | |
diretores[i]='I'; | |
} | |
if(diretores[i]=='Õ'||diretores[i]=='Ó'||diretores[i]=='Ö'||diretores[i]=='Ò'||diretores[i]=='Ô') | |
{ | |
diretores[i]='O'; | |
} | |
if(diretores[i]=='Ú'||diretores[i]=='Ù'||diretores[i]=='Ü'||diretores[i]=='Û') | |
{ | |
diretores[i]='U'; | |
} | |
} | |
diretores[i]='\0'; | |
printf("\nATOR (ES): "); | |
setbuf(stdin, NULL); | |
scanf("%[^\n]s",ator); | |
for(i=0;ator[i]!='\0'; i++) | |
{ | |
ator[i]= toupper(ator[i]); | |
if(ator[i]=='Ã'||ator[i]=='Á'||ator[i]=='Ä'||ator[i]=='À'||ator[i]=='Â') | |
{ | |
ator[i]='A'; | |
} | |
if(ator[i]=='É'||ator[i]=='È'||ator[i]=='Ë'||ator[i]=='Ê') | |
{ | |
ator[i]='E'; | |
} | |
if(ator[i]=='Í'||ator[i]=='Ì'||ator[i]=='Î'||ator[i]=='Ï') | |
{ | |
ator[i]='I'; | |
} | |
if(ator[i]=='Õ'||ator[i]=='Ó'||ator[i]=='Ö'||ator[i]=='Ò'||ator[i]=='Ô') | |
{ | |
ator[i]='O'; | |
} | |
if(ator[i]=='Ú'||ator[i]=='Ù'||ator[i]=='Ü'||ator[i]=='Û') | |
{ | |
ator[i]='U'; | |
} | |
} | |
ator[i]='\0'; | |
insertAll(&inicioFilmes,&inicioAtores,&fimFilmes,&fimAtores,auxInsert,ano,ator,diretores); | |
printf("\n"); | |
} | |
break; | |
case 5: | |
printf("\n VOCE ESCOLHEU A OPÇÃO REMOVER \n "); | |
aq=0; | |
writeFilm=inicioFilmes; | |
//int flagSaber=0; | |
if(writeFilm==NULL) | |
{ | |
printf("\nA Lista de filmes está vazia!\n"); | |
}else{ | |
printf("\n Digite o nome do filme que voce quer remover :"); | |
setbuf(stdin, NULL); | |
scanf("%[^\n]s",auxInsert); | |
for (film = filmes; film != NULL; film = film->next) { | |
if(strcmp(film->next->data,auxInsert)==0) | |
{ | |
film->next=film->next->next; | |
} | |
//tirar da simples | |
} | |
for(i=0;auxInsert[i]!='\0'; i++) | |
{ | |
auxInsert[i]= toupper(auxInsert[i]); | |
if(auxInsert[i]=='Ã'||auxInsert[i]=='Á'||auxInsert[i]=='Ä'||auxInsert[i]=='À'||auxInsert[i]=='Â') | |
{ | |
auxInsert[i]='A'; | |
} | |
if(auxInsert[i]=='É'||auxInsert[i]=='È'||auxInsert[i]=='Ë'||auxInsert[i]=='Ê') | |
{ | |
auxInsert[i]='E'; | |
} | |
if(auxInsert[i]=='Í'||auxInsert[i]=='Ì'||auxInsert[i]=='Î'||auxInsert[i]=='Ï') | |
{ | |
auxInsert[i]='I'; | |
} | |
if(auxInsert[i]=='Õ'||auxInsert[i]=='Ó'||auxInsert[i]=='Ö'||auxInsert[i]=='Ò'||auxInsert[i]=='Ô') | |
{ | |
auxInsert[i]='O'; | |
} | |
if(auxInsert[i]=='Ú'||auxInsert[i]=='Ù'||auxInsert[i]=='Ü'||auxInsert[i]=='Û') | |
{ | |
auxInsert[i]='U'; | |
} | |
} | |
auxInsert[i]='\0'; | |
// atormovie=inicioAtores; | |
while(writeFilm!=NULL) | |
{ | |
if(strcmp(auxInsert,writeFilm->nome)==0) | |
{ | |
aq=1; | |
//atormovie | |
} | |
writeFilm=writeFilm->next; | |
} | |
if(aq==0) | |
{ | |
printf("\nFilme não está na lista!\n"); | |
} else if(aq==1) | |
{ | |
printf("\nPREPARANDO REMOÇÃO DE ELEMENTO...\n"); | |
excluirPrincipal(auxInsert,&inicioFilmes,&fimFilmes); | |
excluirAtRef(auxInsert,&inicioAtores,&fimAtores); | |
/// FUNÇÃO PRINCIPAL | |
printf("\n REMOÇÃO DA LISTA FILME CONCLUIDO\n\n"); | |
//dois whiles agora um para achar o ator e outro pra achar o filme dentro do ator | |
} | |
break; | |
case 6: | |
system("cls"); | |
break; | |
case 0: | |
printf("\nSaindo do programa..."); | |
break; | |
} | |
} | |
}while(option!=0); | |
printf("\nPROGRAMA ENCERRADO:"); | |
system ( "date /t" ); | |
printf("\nHORA FINAL:"); | |
system ("time /t"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment