Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define tam 20
- typedef struct endereco{
- char rua[100], numero[5], bairro[50];
- }Tendereco;
- typedef struct fone{
- char res[12], com[12], cel[12];
- }Tfone;
- typedef struct contato{
- char nome[100], emails[3][50];
- Tendereco ender;
- Tfone fones;
- }Tcontato;
- void preencher(Tcontato agenda[]);
- int consultar(Tcontato agenda[], char nome[]);
- void exibir(Tcontato agenda);
- int main() {
- Tcontato agenda[tam];
- char nome[100],resp;
- int pos;
- preencher(agenda);
- do{
- printf("\nInforme o nome a consultar: ");
- fgets(nome,99,stdin);fflush(stdin);
- pos=consultar(agenda,nome);
- if(pos!=-1)
- exibir(agenda[pos]);
- else
- printf("\nA pessoa nao esta cadastrada!");
- do{
- printf("\nDeseja consultar outra nome?");
- resp=toupper(getchar());fflush(stdin);
- }while(resp!='S'&&resp!='N');
- }while(resp=='S');
- return 0;
- }
- void preencher(Tcontato agenda[]){
- int i, qtd=0;
- char resp;
- for(i=0;i<tam;i++){
- printf("\nInforme o nome: ");
- fgets(agenda[i].nome,99,stdin);fflush(stdin);
- do{
- strcpy(agenda[i].fones.res," ");
- strcpy(agenda[i].fones.com," ");
- strcpy(agenda[i].fones.cel," ");
- printf("\nInforme o email:");
- fgets(agenda[i].emails[qtd],49,stdin);fflush(stdin);
- qtd++;
- do{
- printf("\nDeseja cadastrar outro email?");
- scanf("%c",&resp);fflush(stdin);
- resp=toupper(resp);
- }while(resp!='S'&&resp!='N');
- }while(resp='S'&&qtd<3);
- printf("\nInforme a rua:");
- fgets(agenda[i].ender.rua,99,stdin);fflush(stdin);
- printf("\nInforme o numero:");
- fgets(agenda[i].ender.numero,4,stdin);fflush(stdin);
- printf("\nInforme o bairro:");
- fgets(agenda[i].ender.bairro,44,stdin);fflush(stdin);
- printf("\nTELEFONES");
- do{
- printf("\n1-Residencial 2-Comercial 3-Celular 4-Sair");
- scanf("%c",&resp);fflush(stdin);
- switch(resp){
- case'1': printf("\nInforme o fone:");
- fgets(agenda[i].fones.res,11,stdin);fflush(stdin);
- break;
- case'2': printf("\nInforme o fone:");
- fgets(agenda[i].fones.com,11,stdin);fflush(stdin);
- break;
- case'3': printf("\nInforme o fone:");
- fgets(agenda[i].fones.cel,11,stdin);fflush(stdin);
- break;
- case'4': break;
- }
- }while(resp!='4');
- }
- }
- int consultar(Tcontato agenda[], char nome[]){
- int i;
- for(i=0;i<tam;i++){
- if(strcmp(agenda[i].nome,nome)==0)
- return i;
- else
- return -1;
- }
- }
- void exibir(Tcontato agenda){
- int i;
- printf("\nNome: %s",agenda.nome);
- for(i=0;i<3;i++)
- printf("\nEmail: %s",agenda.emails[i]);
- printf("\nEndereco: %s, %s, %s.",agenda.ender.rua, agenda.ender.numero,agenda.ender.bairro);
- printf("\n-FONES-");
- printf("\nResidencial: %s\nComercial: %s\nCelular: %s",agenda.fones.res,agenda.fones.com,agenda.fones.cel);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement