Sei sulla pagina 1di 9

#include <stdio.

h>
#include <string.h>
#include <stdlib.h>
typedef struct Agenda{
char nome[50];
char fone[17];
}T_agenda;
T_agenda Tab[50];
int total = 0;
void inclusao(void)
{
char op;
op = 's';
while ((total < 50) && (op == 's'))
{
printf("Nome: ");
scanf("%s",&Tab[total].nome[0]);
printf("telefone: ");
scanf("%s",&Tab[total].fone[0]);
printf("deseja inserir mais dados?(s)ou(n)");
scanf("%s",&op);
total++;
}
}
void ordenar(void)
{
int i,j;
char temp[50];
for (i=0 ;i<total;i++)
{
for (j=0;j<total-1;j++)
{
if (strcmp(Tab[j].nome,Tab[j+1].nome)>0)
{
strcpy(temp,Tab[j].nome);
strcpy (Tab[j].nome,Tab[j+1].nome);
strcpy(Tab[j+1].nome,temp);
}
}
}
}
void pesquisar(void)
{
char pesq[20];
int i;
printf("entre com o nome que deseja pesquisar");
scanf("%s",&pesq[0]);
for (i= 0;i<total;i++)

{
if (strcmp(Tab.nome,pesq)== 0)
{
printf("Fone:%s",Tab.fone);
}
}
}
void Listar(void)
{
int i ;
i=0;
while (i < total)
{
printf("%d)Nome:%s Fone:%s\n",i+1,Tab.nome,Tab.fone);
i++;
}
}
void menu(void)
{
char op;
do
{ printf("\n(1)Incluir\n(2)Listar\n(3)Ordenar por nome\n(4)Pesquisar por nome");
scanf("%s",&op);
switch(op)
{
case '1':inclusao();
break;
case '2':Listar();
break;
case '3':eek:rdenar();
break;
case '4':pesquisar();
break;
}
}
while (op != '5');
}
int main ()
{
menu();
return 0;
}
----------------------------------------------------------------------------------------------------------------------------------------------------------#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
struct agenda {
char nome[20];

char endereco[30];
struct agenda *prox;
struct tel *t;
struct mail *m;
};
struct tel{
char telefone[20];
struct tel *prox;
};
struct mail{
char email[30];
struct mail *prox;
};
struct agenda* criaAgenda (){
return NULL;
}
struct tel* criaTel(){
return NULL;
}
struct mail*criaMail(){
return NULL;
}
void insereTel(struct tel **t,char tel[]){
struct tel *p,*q;
p=(struct tel*)malloc(sizeof(struct tel));
strcpy(p->telefone,tel);
p->prox=*t;
*t=p;
}

void insereMail(struct mail **m,char mail[]){


struct mail *p;
p=(struct mail*)malloc(sizeof(struct mail));
strcpy(p->email,mail);
p->prox=*m;
*m=p;
}
void inserePessoa (struct agenda **L, struct tel *T,struct mail *M, char n[], ch
ar end[]){
struct agenda *p;
p=(struct agenda*)malloc(sizeof(struct agenda));
strcpy(p->nome,n); strcpy(p->endereco,end);
p->prox=*L;
p->t=T;

p->m=M;
*L=p;
}
struct agenda* localiza(struct agenda *L,char n[]){
struct agenda *p;
struct tel *auxt;
struct mail *auxm;
int cont=0;
p=L;
auxt=p->t;
auxm=p->m;
while(p!=NULL){
if (strcmp(p->nome,n)!=0)
p=p->prox;
else{
printf("\n\nNome -> %s",p->nome);
printf("\n\nEndereco -> %s",p->endereco);
while(auxt!=NULL){
printf("\n\nTelefone -> %s",auxt->telefone);
auxt =auxt->prox;
}
while (auxm!=NULL){
printf("\n\nemail -> %s",auxm->email);
auxm=auxm->prox;
}
return p;
}
}
return NULL;
}
void listarTodos(struct agenda *L){
struct agenda *p;
struct tel *auxt;
struct mail *auxm;
p=L;
auxt=p->t;
auxm=p->m;
while (p!=NULL){
printf("\n\nNome -> %s",p->nome);
printf("\n\nEndereco -> %s",p->endereco);
while(auxt!=NULL){
printf("\n\nTelefone -> %s",auxt->telefone);
auxt =auxt->prox;
}
while (auxm!=NULL){
printf("\n\nemail -> %s",auxm->email);
auxm=auxm->prox;
}
p=p->prox;
printf("\n\n=================\n\n");
}
}

void listaLetra(struct agenda *L,char n){


struct agenda *p;
struct tel *auxt;
struct mail *auxm;
p=L;
auxt=p->t;
auxm=p->m;
while (p!=NULL){
if(p->nome[0]!=n)
p=p->prox;
else{
printf("\n\nNome -> %s",p->nome);
printf("\n\nEndereco -> %s",p->endereco);
while(auxt!=NULL){
printf("\n\nTelefone -> %s",auxt->telefone);
auxt=auxt->prox;
}
while (auxm!=NULL){
printf("\n\nemail -> %s",auxm->email);
auxm=auxm->prox;
}
p=p->prox;
printf("\n\n======================\n\n");
}
}
}
void alterarDados(struct agenda *L,char n[]){
int cont=0;
struct agenda *p;
struct tel *auxt;
struct mail *auxm;
auxt=p->t;
auxm=p->m;
p=localiza(L,n);
if(p==NULL)
printf("\nNome no encontrado");
else{
printf("\n\nDigite o novo endereco:");
scanf("%s",&p->endereco);
while (auxt!=NULL){
printf("\n\n Digite o novo telefone:");
scanf("%s",&auxt->telefone);
auxt=auxt->prox;
}
while (auxm!=NULL){
printf("\n\n Digite o novo email:");
scanf("%s",&auxm->email);
auxm=auxm->prox;
}
}
}
struct agenda* removerNome(struct agenda *L,char n[]){
struct agenda *p, *q;
p=localiza(L,n);
if (p==NULL)
printf("\nNome nao encontrado");
else{

q=L;
if(q==p){
L=p->prox;
free(p);
}else{
while (q->prox!=p)
q=q->prox;
q->prox=p->prox;
free(p);
}
printf("\n\nPessoa removido com sucesso");
}
return L;
}

main(){
struct agenda *Lista;
struct tel *Tel;
struct mail *Mail;
int op;
char nome[20], endereco[30], telefone[20], email[20];
char no;
Lista=criaAgenda();
Tel=criaTel();
Mail=criaMail();
do{
system("cls");
printf("\n\n===Agenda telefonica eletronia===\n");
printf("\n1 - inserir");
printf("\n2- localiza");
printf("\n3-Listas todos");
printf("\n4-Listar por Letra");
printf("\n5-Alterar dados de uma pessoa");
printf("\n6 -Remover pessoa");
printf("\nOpo==>
");
fflush(stdin);
scanf("%d",&op);
switch (op){
case 1: printf("\n NOme:");
fflush(stdin);
scanf("%s",nome);
printf("\n endereco:");
fflush(stdin);
scanf("%s",endereco);
do{
printf("\n telefone:");
fflush(stdin);
scanf("%s",telefone);
insereTel(&Tel,telefone);
printf("\n possui mais telefone? <1>sim <2>no\n\n");
scanf("%d",&op);

}while(op!=2);
do{
printf("\nemail:");
fflush(stdin);
scanf("%s", email);
insereMail(&Mail,email);
printf("\n possui mais mail? <1>sim <2>no\n\n");
scanf("%d",&op);
}while(op!=2);
inserePessoa(&Lista,Tel,Mail,nome,endereco);
break;
case 2: if(Lista==NULL)
printf("\nAgenda vazia");
else{
printf("\n Digite um nome:");
fflush(stdin);
scanf("%s",nome);
if(localiza(Lista,nome)==NULL)
printf("\n Nome no encontrado na agenda");
}
getch();
break;
case 3: if(Lista==NULL)
printf("\nAgenda vazia");
else
listarTodos(Lista);
getch();
break;
case 4: if(Lista==NULL)
printf("\nAgenda vazia");
else{
printf("Digite uma letra pra busca:");
fflush(stdin);
scanf("%c",&no);
listaLetra(Lista,no);
getch();
}
break;
case 5: if(Lista==NULL)
printf("\nAgenda vazia");
else{
printf("Digite o nome que deseja alterar os dados:");
scanf("%s",nome);
alterarDados(Lista,nome);
getch();
}
break;
case 6: if(Lista==NULL)
printf("\nAgenda vazia");
else{
printf("\nDigite o nome que deseja remover da agenda:");
scanf("%s",nome);
Lista=removerNome(Lista,nome);
getch();
}
}

}while (op!=0);
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

#include
#include
#include
#include

<stdio.h>
<stdlib.h>
<conio.h>
<string.h>

struct agenda {
char nome[20];
char endereco[30];
struct agenda *prox;
struct tel *t;
struct mail *m;
};
struct tel{
char telefone[20];
struct tel *prox;
};
struct mail{
char email[30];
struct mail *prox;
};
struct agenda* criaAgenda (){
return NULL;
}
struct tel* criaTel(){
return NULL;
}
struct mail*criaMail(){
return NULL;
}
void insereTel(struct tel **t,char tel[]){
struct tel *p,*q;
p=(struct tel*)malloc(sizeof(struct tel));
strcpy(p->telefone,tel);
p->prox=*t;
*t=p;
}
void insereMail(struct mail **m,char mail[]){
struct mail *p;
p=(struct mail*)malloc(sizeof(struct mail));
strcpy(p->email,mail);
p->prox=*m;
*m=p;
}
Agora, o que falta , para inserir novos elementos nas funes "insereTel" e "insereMa
il", basta percorrer os ponteiros at o final e inserir o novo elemento criado.

Exemplo:
Cdigo (Text):
void insereTel(struct tel **t,char tel[]){
struct tel *p,*q;
p=(struct tel*)malloc(sizeof(struct tel));
strcpy(p->telefone,tel);
while ( *(t)->prox != NULL )
*(t)->prox;
*(t)->prox=p;
}

Potrebbero piacerti anche