Autor: Josue Leite | Publicado: 2012-05-23T09:58:00-07:00


É muito comum professores passarem trabalhos de criação de sistemas para cadastrar clientes, vou colocar um&nbsp;código&nbsp;aqui q vai ajudar muita gente,deu um trabalho&nbsp;considerável&nbsp;construí-lo, porem quem&nbsp;não&nbsp;tiver tempo como eu&nbsp;não&nbsp;tinha pode se aproveitar desse aqui.Ele faz o uso de funções para string,arquivos,do windows e o mais complicado tratamento de erros como é um trabalho pra iniciantes&nbsp;não&nbsp;faz uso de malloc,listas,nem arvores binarias é bem&nbsp;básico&nbsp;mesmo pra quem tiver interesse em começar a entender &nbsp;a criação de um banco de dados, bem , muita coisa pode ser modificada pra otimizar o sistema,mas funciona espero q ajude muitos.Este é um programa para banco que cadastra um cliente em uma struct com 10 campos e salva no arquivo informações.Tem funções de validação de cpf,data, faltam alguns ajustes pra tratar os erros de edição e cadastro de strings maiores que &nbsp;o definido na struct, mas pode ser resolvido limitando a inserção de dados a um tamanho definido como feito com a função recebe_data,ainda irei implementar esta parte, quem quiser testar pra saber se existem mais erros posto aqui o&nbsp;código&nbsp;dele, vc precisará da biblioteca conio2.h&nbsp;disponível&nbsp;no link&nbsp;http://bccfema.ingoo.us/t1-biblioteca-conio2h&nbsp;.
Alem de cadastrar,salvar,editar e excluir o sistema faz pesquisa por nome, data de criação,saldo e outras.
agradeço os q tentarem contribuir.Postem aqui as modificações e comentem o&nbsp;código, como estou com pressa vou mandar o&nbsp;código com os poucos&nbsp;comentários&nbsp;q tem&nbsp; e depois q ele estiver melhor vou comentando e aprimorando pra&nbsp;vocês&nbsp;acompanharem as mudanças e&nbsp;evoluções.O ideal é usar compilação separada mas vou postar o&nbsp;código&nbsp;em um só arquivo e quem estiver interessado posta aqui que eu auxilio a dividir em&nbsp;vários&nbsp;arquivos.Pode precisar de bibliotecas adicionais mas no meu pc esta rodando apenas com essas.


#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;windows.h&gt;
#define clrscr() (system("cls"))
char SISTEMA[33]="PROGRAMA DE CADASTRO DE CLIENTES";
char INVALIDO[16]="CPF INVALIDO";

void gotoxy(int x, int y){
&nbsp; &nbsp; COORD coord;
&nbsp; &nbsp; coord.X=(short)x;
&nbsp; &nbsp; coord.Y=(short)y;
&nbsp; &nbsp; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void clearline(void){
&nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ");
&nbsp; &nbsp; return;
}
void center(int LINHA, char *MENSAGEM){
&nbsp; &nbsp; int COLUNA;
&nbsp; &nbsp; COLUNA = ((80-strlen(MENSAGEM))/2);
&nbsp; &nbsp; gotoxy(COLUNA,LINHA);
&nbsp; &nbsp; printf(MENSAGEM);
&nbsp; &nbsp; return;
}
void line(void){
&nbsp; &nbsp; int POSICAO;

&nbsp; &nbsp; for(POSICAO=0;POSICAO&lt;80;POSICAO++)
&nbsp; &nbsp; &nbsp; &nbsp; printf("$");
&nbsp; &nbsp; for(POSICAO=0;POSICAO&lt;80;POSICAO++)
&nbsp; &nbsp; &nbsp; &nbsp; printf("+");
&nbsp; &nbsp; return;
}
char* recebe_data(void)
{
&nbsp; &nbsp; int cont;
&nbsp; &nbsp; char tecla;
&nbsp; &nbsp; char data[11];

&nbsp;for(cont=0;cont&lt;10;cont++)
&nbsp; &nbsp; data[cont] = ' ';

&nbsp;data[2] = data[5] = '/'; data[10] = '\0';

&nbsp; &nbsp; cont=0;
&nbsp;do
&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(12,4);
&nbsp; &nbsp; &nbsp; &nbsp; printf("Data: %s",data);

&nbsp; tecla = getch();

&nbsp; if(tecla==(char)13)
&nbsp; {
&nbsp; &nbsp;if(cont&lt;9)
&nbsp; &nbsp;{
&nbsp; &nbsp; data[cont]=NULL;
&nbsp; &nbsp; tecla = NULL ;
&nbsp; &nbsp;}
&nbsp; }
&nbsp; else if(tecla==(char)8)
&nbsp; {
&nbsp; &nbsp;if(cont&gt;0)
&nbsp; &nbsp;{
&nbsp; &nbsp; cont--;
&nbsp; &nbsp; if(cont==2 || cont==5)
&nbsp; &nbsp; &nbsp; &nbsp; cont--;
&nbsp; &nbsp; data[cont] = ' ';
&nbsp; &nbsp;}
&nbsp; }
&nbsp; else if (isdigit(tecla))
&nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(cont&lt;10)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; data[cont] = tecla;
&nbsp; &nbsp; &nbsp; &nbsp; cont++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp;if(cont==2 || cont==5)
&nbsp; &nbsp; &nbsp; &nbsp; cont++;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp;}
&nbsp;while(tecla!=(char)13);

&nbsp;return(data);
}
int val_cpf(char str[12])
{

&nbsp; &nbsp; &nbsp; int cpf[11];
&nbsp; &nbsp; &nbsp; int vercpf[11];
&nbsp; &nbsp; &nbsp; int d1,d2,d3,d4,aux,i;
&nbsp; &nbsp; &nbsp;// printf(" INSIRA O SEU CPF SEM PONTOS: ");
&nbsp; &nbsp; &nbsp; //scanf ("%s", str);

&nbsp; &nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 11; i++)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; cpf[i]=str[i]-48;
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; //printf("\n");

&nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 11; i++)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; //printf("%d\n",cpf[i]);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; //verificando o primeiro dígito
&nbsp; &nbsp; &nbsp; aux = 10;
&nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 9; i++)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; vercpf[i] = cpf[i] * aux;
&nbsp; &nbsp; &nbsp; &nbsp; aux &nbsp;= aux - 1;
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; aux = 0;
&nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 9; i++)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; aux = vercpf[i] + aux;
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; d1 = aux / 11;
&nbsp; &nbsp; &nbsp; d2 = d1 * 11;
&nbsp; &nbsp; &nbsp; d3 = aux - d2;

&nbsp; &nbsp; &nbsp; if(d3 &lt;= 1)
&nbsp; &nbsp; &nbsp; &nbsp; d3 = 0;
&nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; d3 = 11 - d3;

&nbsp; &nbsp; &nbsp; //printf(" Digito verificador 1: %d",d3);
&nbsp; &nbsp; &nbsp; //printf("\n");

&nbsp; &nbsp; &nbsp; //verificando o segundo dígito
&nbsp; &nbsp; &nbsp; d1 = 0;
&nbsp; &nbsp; &nbsp; d2 = 0;
&nbsp; &nbsp; &nbsp; d4 = 0;
&nbsp; &nbsp; &nbsp; aux = 11;

&nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 10; i++)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; vercpf[i] = cpf[i] * aux;
&nbsp; &nbsp; &nbsp; &nbsp; aux &nbsp;= aux - 1;
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; aux = 0;
&nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 10; i++)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; aux = vercpf[i] + aux;
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; d1 = aux / 11;
&nbsp; &nbsp; &nbsp; d2 = d1 * 11;
&nbsp; &nbsp; &nbsp; d4 = aux - d2;

&nbsp; &nbsp; &nbsp; if(d4 &lt;= 1)
&nbsp; &nbsp; &nbsp; &nbsp; d4 = 0;
&nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; d4 = 11 - d4;

&nbsp; &nbsp; &nbsp; //printf(" Digito verificador 2: %d",d4);
&nbsp; &nbsp; &nbsp; //printf("\n\n");

&nbsp; &nbsp; &nbsp; if((d3 != cpf[9]) || (d4 != cpf[10]))
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; //printf(" CPF INVALIDO \n\n");
&nbsp; &nbsp; &nbsp; &nbsp; //val_cpf(str);
&nbsp; &nbsp; &nbsp; &nbsp; return(1);//scanf("%d",d3);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; {
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(" CPF CONFERE...");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(i = 0;i &lt; 11; i++)
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("%d",cpf[i]);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return(0);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; //printf("\n\n");
}


typedef struct Formulario{
&nbsp; &nbsp; int valida;
&nbsp; &nbsp; char nome[50];
&nbsp; &nbsp; char e_mail[50];
&nbsp; &nbsp; char Nasc[15];
&nbsp; &nbsp; char rg[20];
&nbsp; &nbsp; char cpf[20];
&nbsp; &nbsp; char telefone[15];
&nbsp; &nbsp; double saldo;
&nbsp; &nbsp; char end[80];
&nbsp; &nbsp; char cid[30];
&nbsp; &nbsp; char estado[30];
&nbsp; &nbsp; char cep[12];
}REGISTRO;
/*#**/
//Função cadastrar
void cadastrar(){
&nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int opt,cpf[12];
&nbsp; &nbsp; &nbsp; &nbsp; printf("CADASTRAR\n\n");
&nbsp; &nbsp; &nbsp; &nbsp;//Cadastro Informações-Pessoais
&nbsp; &nbsp; &nbsp; &nbsp; printf("Nome:\nE_mail:\nNascimento:\nRG:\nCPF:\nTel:\nSaldo Inicial:\n");
&nbsp; &nbsp; &nbsp; &nbsp;//Cadastro Informações-Endereço
&nbsp; &nbsp; &nbsp; &nbsp; printf("Endereco:\nBairro:\nCidade:\nCEP:");
&nbsp; &nbsp; //Digitar Dados
&nbsp; &nbsp; gotoxy(6,2); fflush(stdin); gets(cliente.nome);
&nbsp; &nbsp; gotoxy(8,3); fflush(stdin); gets(cliente.e_mail);
&nbsp; &nbsp; gotoxy(20,4); recebe_data();fflush(stdin); strcpy(cliente.Nasc,INVALIDO);
&nbsp; &nbsp; gotoxy(4,5); fflush(stdin); gets(cliente.rg);
&nbsp; &nbsp; gotoxy(5,6); scanf("%s",cpf);if(val_cpf(cpf)==0){gotoxy(5,6);fflush(stdin);gets(cliente.cpf);}else {gotoxy(5,6);printf(INVALIDO);strcpy(cliente.cpf,INVALIDO);}
&nbsp; &nbsp; gotoxy(5,7); fflush(stdin); gets(cliente.telefone);
&nbsp; &nbsp; gotoxy(15,8); scanf("%lf", &amp;cliente.saldo);
&nbsp; &nbsp; gotoxy(10,9); fflush(stdin); gets(cliente.end);
&nbsp; &nbsp; gotoxy(8,10); fflush(stdin); gets(cliente.estado);
&nbsp; &nbsp; gotoxy(15,11); fflush(stdin); gets(cliente.cid);
&nbsp; &nbsp; gotoxy(5,12); fflush(stdin); gets(cliente.cep);
&nbsp; &nbsp; cliente.valida=1;
&nbsp; &nbsp; //Salvar Dados
&nbsp; &nbsp; printf("\n1.SALVAR\n0.VOLTAR\n\n: "); scanf("%d", &amp;opt);
&nbsp; &nbsp; if(opt){
&nbsp; &nbsp; &nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","a+b"))){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(!fwrite(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na escrita do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nSeus dados foram salvos com sucesso.");
&nbsp; &nbsp; &nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nDados nao salvos.");
&nbsp; &nbsp; }
&nbsp; &nbsp; system("pause&gt;0");
}
/*#**/
//Imprimir os dados de um cliente
void ImprimirDados(REGISTRO cliente){
&nbsp; &nbsp; system("CLS");

&nbsp; &nbsp; gotoxy(10,7);printf("Nome: %s\n", cliente.nome);
&nbsp; &nbsp; gotoxy(10,8);printf("E_mail: %s\n", cliente.e_mail);
&nbsp; &nbsp; gotoxy(10,9);printf("Nascimento: %s\n", cliente.Nasc);
&nbsp; &nbsp; gotoxy(10,10);printf("RG: %s\n", cliente.rg);
&nbsp; &nbsp; gotoxy(10,11);printf("CPF: %s\n", cliente.cpf);
&nbsp; &nbsp; gotoxy(10,12);printf("Tel: %s\n", cliente.telefone);
&nbsp; &nbsp; gotoxy(10,13);printf("Saldo: %0.2lf\n", cliente.saldo);
&nbsp; &nbsp; gotoxy(10,14);printf("Endereco: %s\n", cliente.end);
&nbsp; &nbsp; gotoxy(10,15);printf("Estado: %s\n", cliente.estado);
&nbsp; &nbsp; gotoxy(10,16);printf("Cidade: %s\n", cliente.cid);
&nbsp; &nbsp; gotoxy(10,17);printf("CEP: %s\n", cliente.cep);
}
/*#**/
//Calcular o numero maximo de clientes
int Max(){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; int Max;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; fseek(arquivo,0,SEEK_END);
&nbsp; &nbsp; Max=ftell(arquivo)/sizeof(REGISTRO);
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return Max;
}
/*#**/
//Consulta "Por Letra"
int p_ini(int N_CLI,char letra){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int i=1, a=0;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; rewind(arquivo);
&nbsp; &nbsp; while(i&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na leitura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if((cliente.nome[0]==letra || cliente.nome[0]==letra+32 || cliente.nome[0]==letra-32) &amp;&amp; cliente.valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n%d-%s", i, cliente.nome);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; i++;
&nbsp; &nbsp; }
&nbsp; &nbsp; printf("\n\n");
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return a;
}
/*#**/
//Consulta "Por Saldo"
int porSaldo(int N_CLI,double saldoMenor,double saldoMaior){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int i=1, a=0;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; rewind(arquivo);
&nbsp; &nbsp; while(i&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na leitura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(cliente.saldo&gt;=saldoMenor &amp;&amp; cliente.saldo&lt;=saldoMaior &amp;&amp; cliente.valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n%d-%s", i, cliente.nome);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; i++;
&nbsp; &nbsp; }
&nbsp; &nbsp; printf("\n\n");
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return a;
}
////Consulta "Por codigo"
//int porCod(int N_CLI,int cod){
// &nbsp; &nbsp;FILE *arquivo;
// &nbsp; &nbsp;REGISTRO cliente;
// &nbsp; &nbsp;int i=1, valida=0;
// &nbsp; &nbsp;if(!(arquivo=fopen("Informacoes.bin","rb"))){
// &nbsp; &nbsp; &nbsp; &nbsp;printf("\nErro na abertura do arquivo.");
// &nbsp; &nbsp; &nbsp; &nbsp;exit(0);
// &nbsp; &nbsp;}
// &nbsp; &nbsp;rewind(arquivo);
// &nbsp; &nbsp;while(i&lt;=N_CLI){
// &nbsp; &nbsp; &nbsp; &nbsp;if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\nErro na leitura do arquivo.");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit(0);
// &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; &nbsp;if(cliente.codigo=cod &amp;&amp; cliente.valida){
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\n%d-%s codigo: %d", i, cliente.nome,cliente.codigo);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;valida=1;
// &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; &nbsp;i++;
// &nbsp; &nbsp;}
// &nbsp; &nbsp;printf("\n\n");
// &nbsp; &nbsp;fclose(arquivo);
// &nbsp; &nbsp;return valida;
//}

//Consulta "Por Ano"
int porAno(int N_CLI,int ano){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int i=1, valida=0;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; rewind(arquivo);
&nbsp; &nbsp; while(i&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na leitura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(ano==2012 &amp;&amp; cliente.valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n%d-%s", i, cliente.nome);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; i++;
&nbsp; &nbsp; }
&nbsp; &nbsp; printf("\n\n");
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return valida;
}
/*#**/
//Consulta "Todos os Clientes" -&gt; Imprimir os nomes de todos os clientes
int todosClientes(int N_CLI){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int i=1, valida=0;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; rewind(arquivo);
&nbsp; &nbsp; while(i&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na leitura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(cliente.valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%d-%s\n", i, cliente.nome);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; i++;
&nbsp; &nbsp; }
&nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return valida;
}
/*#**/
//Consulta "Excluidos"
int excluidos(int N_CLI){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int i=1, valida=0;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; rewind(arquivo);
&nbsp; &nbsp; while(i&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na leitura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(!cliente.valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%d-%s\n", i, cliente.nome);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; i++;
&nbsp; &nbsp; }
&nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return valida;
}
/*#**/
//Consulta "porCliente"
REGISTRO porCliente(int posicao){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","rb"))){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; fseek(arquivo,sizeof(REGISTRO)*posicao,SEEK_SET);
&nbsp; &nbsp; if(!fread(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na leitura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; }
&nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; return cliente;
}
/*#**/
//Função Editar
REGISTRO editar(REGISTRO cliente){
&nbsp; &nbsp; int opcao;
&nbsp; &nbsp; char aux[50];
&nbsp; &nbsp; for(;;){
&nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; &nbsp; &nbsp; printf("EDITAR\n\n");
&nbsp; &nbsp; &nbsp; &nbsp; ImprimirDados(cliente);
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(20,21);printf("\n1.Nome\n2.E_mail\n3.Nascimento\n4.RG\n5.CPF\n6.Tel\n7.Endereco\n8.Bairro\n10.Cidade\n11.CEP\n0.Voltar\n\n: ");
&nbsp; &nbsp; &nbsp; &nbsp; scanf("%d", &amp;opcao);
&nbsp; &nbsp; &nbsp; &nbsp; if(opcao==0) break;
&nbsp; &nbsp; &nbsp; &nbsp; if(opcao==1){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(16,7);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(16,7);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.nome,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==2){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(18,8);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(18,8);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.e_mail,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==3){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(21,9);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(21,9);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.Nasc,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==4){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(14,10);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(14,10);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.rg,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==5){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(15,11);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(15,11);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);if(val_cpf(aux)==0)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.cpf,aux);else strcpy(cliente.nome,INVALIDO);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==6){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(15,12);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(15,12);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.telefone,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==7){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(20,14);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(20,14);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.end,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==8){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(18,15);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(18,15);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.estado,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==10){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(17,16);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(17,16);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.cid,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==11){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(15,17);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gotoxy(15,17);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); gets(aux);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(cliente.cep,aux);
&nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Opcao Invalida.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }
&nbsp; &nbsp; return cliente;
}
/*#**/
//Função Editar ou EXCLUIR ou Depositar ou Retirada e retaurar cliente
void edit(REGISTRO cliente,int posicao){
&nbsp; &nbsp; FILE *arquivo;
&nbsp; &nbsp; int opcao;
&nbsp; &nbsp; double valor;
&nbsp; &nbsp; for(;;){
&nbsp; &nbsp; &nbsp; &nbsp; ImprimirDados(cliente);
&nbsp; &nbsp; &nbsp; &nbsp; if(cliente.valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n&lt;[1]EDITAR [2]EXCLUIR [3]REALIZAR DEPOSITO [4]SAQUE [5]SALVAR [0]VOLTAR &gt;\n\n: ");
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n&lt;[1]EDITAR [2]EXCLUIR [3]REALIZAR DEPOSITO [4]SAQUE [5]SALVAR [0]VOLTAR &gt;\n\n: ");
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; scanf("%d", &amp;opcao);
&nbsp; &nbsp; &nbsp; &nbsp; if(opcao==0) break;
&nbsp; &nbsp; &nbsp; &nbsp; //Editar
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==1) cliente=editar(cliente);
&nbsp; &nbsp; &nbsp; &nbsp; //EXCLUIR ou RECADASTRAR -&gt; Torna o cliente existente ou nao
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==2) cliente.valida=!cliente.valida;
&nbsp; &nbsp; &nbsp; &nbsp; //REALIZAR DEPOSITO
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==3){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nValor do deposito: "); scanf("%lf", &amp;valor);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente.saldo+=valor;
&nbsp; &nbsp; &nbsp; &nbsp; //SAQUE
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==4){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nValor do saque: "); scanf("%lf", &amp;valor);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente.saldo-=valor;
&nbsp; &nbsp; &nbsp; &nbsp; //Salvar
&nbsp; &nbsp; &nbsp; &nbsp; }else if(opcao==5){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!(arquivo=fopen("Informacoes.bin","r+b"))){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na abertura do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fseek(arquivo,sizeof(REGISTRO)*posicao,SEEK_SET);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!fwrite(&amp;cliente,sizeof(REGISTRO),1,arquivo)){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nErro na escrita do arquivo.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(0);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nSeus dados foram salvos com sucesso.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose(arquivo);
&nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Opcao Invalida.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }
}
/*consultar por inicial*/
void c_inicial(){
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; char letra;
&nbsp; &nbsp; int valida,N_CLI=Max(),P_CLI;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("CONSULTA POR INICIAL\n\nINICIAL: ");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fflush(stdin); scanf("%c", &amp;letra);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=p_ini(N_CLI,letra);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("0.VOLTAR\nCliente: "); scanf("%d", &amp;P_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&gt;0){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente=porCliente(P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edit(cliente,P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes nesta posicao.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
}
//Função consultar
void c_all(){
&nbsp; &nbsp; REGISTRO cliente;
&nbsp; &nbsp; int N_CLI=Max(),opcao, P_CLI, ano, valida;
&nbsp; &nbsp; char letra;
&nbsp; &nbsp; double maxSaldo, minSaldo;
&nbsp; &nbsp; for(;;){
&nbsp; &nbsp; &nbsp; &nbsp; valida=0;
&nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; &nbsp; &nbsp; printf("CONSULTAR\n\n[1]-POR SALDO [2]-POR ANO [3]-TODOS OS CLIENTES [4]-ROL DOS EXCLUIDOS\n[0]-VOLTAR\n\n: ");
&nbsp; &nbsp; &nbsp; &nbsp; scanf("%d", &amp;opcao);
&nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; &nbsp; &nbsp; //Voltar
&nbsp; &nbsp; &nbsp; &nbsp; if(opcao==0) break;
&nbsp; &nbsp; &nbsp; &nbsp; //Por Saldo
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==1){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("POR SALDO\n\nDigite um intervalo de valores &nbsp;min &lt; saldo &lt; max ");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nMin: "); scanf("%lf", &amp;minSaldo);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Max: "); scanf("%lf", &amp;maxSaldo);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=porSaldo(N_CLI,minSaldo,maxSaldo);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("0.VOLTAR\nCliente: "); scanf("%d", &amp;P_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&gt;0){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente=porCliente(P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edit(cliente,P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes nesta posicao.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes nesse intervalo.\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; //Por Ano
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==2){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("POR ANO\n\nAno: ");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d", &amp;ano);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=porAno(N_CLI,ano);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("0.VOLTAR\nCliente: "); scanf("%d", &amp;P_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&gt;0){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente=porCliente(P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edit(cliente,P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes nesta posicao.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes cadastrados nesse ano.\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp; //Todos os clientes
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==3){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("TODOS OS CLIENTES\n\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=todosClientes(N_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("0.VOLTAR\nCliente: "); scanf("%d", &amp;P_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&gt;0){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente=porCliente(P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edit(cliente,P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes nesta posicao.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes cadastrados.\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; //Excluidos
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==4){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("EXCLUIDOS\n\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valida=excluidos(N_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(valida){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("0.VOLTAR\nCliente: "); scanf("%d", &amp;P_CLI);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&gt;0){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(P_CLI&lt;=N_CLI){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cliente=porCliente(P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edit(cliente,P_CLI-1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes nesta posicao.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Nao ha clientes excluidos.\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; else if(opcao==6){printf("POR CODIGO\n\nCod: ");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fflush(stdin); scanf("%d", &amp;cod);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;valida=porCod(N_CLI,cod);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(valida){
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("0.VOLTAR\nCliente: "); scanf("%d", &amp;P_CLI);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(P_CLI&gt;0){
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(P_CLI&lt;=N_CLI){
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cliente=porCliente(P_CLI-1);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;edit(cliente,P_CLI-1);
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}else{
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("Nao ha clientes nesta posicao.");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;system("pause&gt;0");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else{
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("Nao ha clientes com esse nome.\n");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;system("pause&gt;0");
// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
// &nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp; else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("CONSULTAR\n\n1-POR LETRA\n2-POR SALDO\n3-POR ANO\n4-TODOS OS CLIENTES\n5-EXCLUIDOS\n0-VOLTAR\n\n: %d\nOpcao Invalida.", opcao);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }
}
/*#**/
//Função principal
int main(){
&nbsp; &nbsp; int opcao,cp[12];
&nbsp; &nbsp; for(;;){
&nbsp; &nbsp; &nbsp; &nbsp; system("COLOR 84");
&nbsp; &nbsp; &nbsp; &nbsp; clrscr();
&nbsp; &nbsp; &nbsp; &nbsp; line();
&nbsp; &nbsp; &nbsp; &nbsp; center(2,SISTEMA);
&nbsp; &nbsp; &nbsp; &nbsp; center(3,"Menu de Opcoes");

&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,10);printf("1-CADASTRAR CLIENTE");
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,11);printf("2-CONSULTAS VARIADAS");
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,12);printf("3-VALIDACAO DE CPF");
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,13);printf("4-CONSULTAR POR INICIAL DO NOME");
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,14);printf("5-DELETAR CLIENTE");

&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,17);printf("0-SAIR DO SISTEMA");
&nbsp; &nbsp; &nbsp; &nbsp; gotoxy(26,19);scanf("%d", &amp;opcao);
&nbsp; &nbsp; &nbsp; &nbsp; if(opcao==0) break;
&nbsp; &nbsp; &nbsp; &nbsp; //Fazer cadastro
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==1) cadastrar();
&nbsp; &nbsp; &nbsp; &nbsp; //Fazer consulta
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==2) c_all();
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==3){scanf("%s",cp);if(val_cpf(cp)==0){printf("Cpf válidado pela receita federal");system("pause&gt;0");}else{printf("cpf invalido"); system("pause&gt;0");}
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==4) c_inicial();
&nbsp; &nbsp; &nbsp; &nbsp; else if(opcao==5) printf("Ja vai");
&nbsp; &nbsp; &nbsp; &nbsp; else{
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Opcao Invalida.");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system("pause&gt;0");
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; system("CLS");
&nbsp; &nbsp; }
&nbsp; &nbsp; return 0;
}