Gente, alguns dias atras postei meu codigo aki, consegui completar o programa, porem tenho 2 problemas, na hra q eu volto ao menu dps de cadastrar os clientes, tenho q ficar apertando a opcao varias vezes pra ele entrar na funcao, não sei porque isso, e o outro é q eu preciso salvar em arquivo .dat, e se por acaso ele existir no diretorio ele carregar...
ps: tenho q salvar o arquivo em funcionarios.dat, se ele existir no diretorio ele carrega.
por favor, já pesquisei aki, não consegui, se alguém souber, me ajuda ae...
to postando meu codigo ai...
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include <windows.h>
/*-----------------Cores do DOS-------------------------------------------------
Descrição: Procedimento para definição de Cores do DOS
------------------------------------------------------------------------------*/
enum DOS_COLORS {
BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN,
LIGHT_GRAY, DARK_GRAY, LIGHT_BLUE, LIGHT_GREEN, LIGHT_CYAN,
LIGHT_RED, LIGHT_MAGENTA, YELLOW, WHITE };
/*----------------------------------------------------------------------------*/
/*-----------------Cores das letras---------------------------------------------
Descrição: Procedimento para inserir cores de letras no programa
------------------------------------------------------------------------------*/
void textcolor (DOS_COLORS iColor)
{
HANDLE hl = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
BOOL b = GetConsoleScreenBufferInfo(hl, &bufferInfo);
bufferInfo.wAttributes &= 0x00F0;
SetConsoleTextAttribute (hl, bufferInfo.wAttributes |= iColor);
}
int cadastro (struct cad*); // REGISTRO DOS DADOS
struct cad{
char nome[20];
char end[22];
char ecivil[22];
int numcliente[2];
char fone[10];
char rg[22];
char data[10];
char cic[22];
char dep[3];
};
//DECLARAÇAO DAS VARIAVEIS
//------------------------------------------------------------------------------
int op;
struct cad dados[3];
int ch,opcao,cont,pesq,volta;
int decisao;
//FUNCAO DO MENU
int menu (void){
textcolor(YELLOW);
printf("\n\t\t\t:::::::::::FIRESTORM:::::::::::::");
printf("\n________________________________________________________________________________");
textcolor(LIGHT_CYAN);
printf("\n");
printf("\n");
printf("\n\t\t <<<<<<<<MENU DE CADASTRO>>>>>>>>");
printf("\n");
printf("\n\t\t [ 1 ] - ADICIONAR UM NOVO CADASTRO ");
printf("\n\t\t [ 2 ] - PESQUISAR CADASTROS ");
printf("\n\t\t [ 3 ] - SAIR ");
printf("\n");
printf("\n");
printf(" "" ] - DIGITE A OPCAO DESEJADA " );printf("\r");printf(" [ ");printf("");
scanf("%d",&op);
system ("cls");
return (op);
}
//FUNCAO DO CADASTRO
//------------------------------------------------------------------------------
int cadastro(){
textcolor(YELLOW);
printf("\t\t\t\n\t\t\t:::::::::::FIRESTORM::::::::::::: ");
printf("\n________________________________________________________________________________");
textcolor(LIGHT_CYAN);
for (cont=0;cont<3;cont++){ cont+1;
printf("\n\n\n\t\t\t ADICIONANDO REGISTRO.. ");
printf("\n\n\nCADASTRE O CLIENTE : \n");
printf("\n\n\nNumero de cadastro_____________________ : ");
scanf("%d",&dados[cont].numcliente);
printf("\nInsira o nome__________________________ : ");
scanf("%s",&dados[cont].nome);
printf("\nInsira o Endereco______________________ : ");
scanf("%s",&dados[cont].end);
printf("\nInsira o Telefone______________________ : ");
scanf("%s",&dados[cont].fone);
printf("\nInsira o Estado civil__________________ : ");
scanf("%s",&dados[cont].ecivil);
printf("\nInsira o RG :___________________________: ");
scanf("%s",&dados[cont].rg);
printf("\nInsira o CIC___________________________ : ");
scanf("%s",&dados[cont].cic);
printf("\nInsira a data de nascimento____________ : ");
scanf("%s",&dados[cont].data);
printf("\nInsira a quantidade de dependentes____ : ");
scanf("%s",&dados[cont].dep);
printf("\n\t::::::CADASTRO REALIZADO COM SUCESSO::::::");
printf("\n\n");
printf("\n\n"); textcolor(YELLOW);
printf("\n DESEJA REALMENTE REALIZAR O CADASTRO?(1-SIM 2-não) - ");
scanf("%d",&decisao);textcolor(LIGHT_CYAN);
switch (decisao){
case 1 : continue; //system("cls");return cadastro();
case 2 : system("cls");return menu();
default:textcolor(LIGHT_RED); printf("\n \t O P C A O I N V A L I D A (VOLTANDO AO MENU PRINCIPAL...) ");textcolor(LIGHT_CYAN);getch();
system("cls");return menu();
}
}
system("cls");
return(0);
}
//FUNCAO DE PESQUISA
//------------------------------------------------------------------------------
int pesquisa (){textcolor(YELLOW);
printf("\n\t\t\t::::::PESQUISA DE CLIENTES:::::: ");
printf("\n________________________________________________________________________________");
textcolor(LIGHT_CYAN);
printf("\n\n");
printf(" "" ] - DIGITE O NUMERO DE CADASTRO " );printf("\r");printf(" [ ");printf("");
scanf("%d",&ch);
pesq = 0;
for (cont=0;cont<3;cont++){
if(ch==*dados[cont].numcliente){
printf("\n CADASTRO ENCONTRADO : \n ");
printf("\n");
//EXIBIÇÃO DOS DADOS PESQUISADOS
printf("\n\tCADASTRO No. %d",*dados[cont].numcliente);
printf("\n________________________________");
printf("\n");
printf("\n\t NOME_________________- %s", dados[cont].nome);
printf("\n\t ENDERECO_____________- %s", dados[cont].end);
printf("\n\t TEL:_________________- %s", dados[cont].fone);
printf("\n\t ESTADO CIVIL_________- %s", dados[cont].ecivil);
printf("\n\t RG___________________- %s", dados[cont].rg);
printf("\n\t CIC__________________- %s", dados[cont].cic);
printf("\n\t DATA DE NASCIMENTO___- %s", dados[cont].data);
printf("\n\t NUMERO DEPENDENTES___- %s", dados[cont].dep);
printf("\n");
pesq =1;
return(0);
}
}
if (pesq==0){textcolor(LIGHT_RED);
printf("\n\n\t\tCADASTRO não ENCONTRADO, TENTE NOVAMENTE...\n\n\n");
getch();
system("cls");
menu();
}
}
//TELA PRINCIPAL
//------------------------------------------------------------------------------
int main (){
{textcolor(LIGHT_CYAN);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");textcolor(YELLOW);
printf("\n\t ##### ## ###### ##### ####### ####### #### ####");
printf("\n\t ##### ## ## ## ### ## ###### ## ## #### ####");
printf("\n\t ## ## ## ## ## ## ####### # # ## ## ## ## ## ## ");
printf("\n\t##### ## ###### ##### ####### ## ## ## ###### ## ## ##");
printf("\n\t## ## ## ## #### ## ## ## ## ## ## ## ##");
printf("\n\t## ## ## ## ## ## ## ## ## ## ## ## ##");
printf("\n\t## ## ## # ##### ####### ## ######## ## ## ## ## TM*");
printf("\n\n\n\n\t\t F I R E S T O R M* S/A @ \n\t\t\t\t\t\t\tSolucoes pra você.\n");textcolor(LIGHT_CYAN);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
//printf("GRUPO: David Mauricio; Bianca Ferraz; Michel Lima; Angelli Nascimento");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
textcolor(WHITE);
printf("Press ENTER...");textcolor(LIGHT_CYAN);
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
}
getch();
system("cls");
decisao=0;
opcao=menu();
//CHAMANDO AS FUNÇOES
//------------------------------------------------------------------------------
while(op!=3){
if (op==1){
cadastro();
opcao=menu();
// while (cont==3)
if(cont==3){
textcolor(LIGHT_RED);
printf("AGENDA LOTADA");}
menu();
opcao=menu();
}
if (op==2){
pesquisa();
opcao=menu();
}
if (op==3){
printf("\n\n\t\t\t\n\n\n\nSAINDO DO PROGRAMA...\n\n\n\n\n\n\n\n");
}
if(op>3) {textcolor(LIGHT_RED);
printf("\t\t\tESCOLHA UMA OPCAO VALIDA");
opcao=menu();}
}
printf("XAU !!!");
getch();
return(0);
}
Editado por Jonathan Queiroz Adcionar tag's (Jonathan)
Pergunta
L0mbra
Gente, alguns dias atras postei meu codigo aki, consegui completar o programa, porem tenho 2 problemas, na hra q eu volto ao menu dps de cadastrar os clientes, tenho q ficar apertando a opcao varias vezes pra ele entrar na funcao, não sei porque isso, e o outro é q eu preciso salvar em arquivo .dat, e se por acaso ele existir no diretorio ele carregar...
ps: tenho q salvar o arquivo em funcionarios.dat, se ele existir no diretorio ele carrega.
por favor, já pesquisei aki, não consegui, se alguém souber, me ajuda ae...
to postando meu codigo ai...
#include<stdio.h> #include<conio.h> #include<iostream.h> #include <windows.h> /*-----------------Cores do DOS------------------------------------------------- Descrição: Procedimento para definição de Cores do DOS ------------------------------------------------------------------------------*/ enum DOS_COLORS { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHT_GRAY, DARK_GRAY, LIGHT_BLUE, LIGHT_GREEN, LIGHT_CYAN, LIGHT_RED, LIGHT_MAGENTA, YELLOW, WHITE }; /*----------------------------------------------------------------------------*/ /*-----------------Cores das letras--------------------------------------------- Descrição: Procedimento para inserir cores de letras no programa ------------------------------------------------------------------------------*/ void textcolor (DOS_COLORS iColor) { HANDLE hl = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO bufferInfo; BOOL b = GetConsoleScreenBufferInfo(hl, &bufferInfo); bufferInfo.wAttributes &= 0x00F0; SetConsoleTextAttribute (hl, bufferInfo.wAttributes |= iColor); } int cadastro (struct cad*); // REGISTRO DOS DADOS struct cad{ char nome[20]; char end[22]; char ecivil[22]; int numcliente[2]; char fone[10]; char rg[22]; char data[10]; char cic[22]; char dep[3]; }; //DECLARAÇAO DAS VARIAVEIS //------------------------------------------------------------------------------ int op; struct cad dados[3]; int ch,opcao,cont,pesq,volta; int decisao; //FUNCAO DO MENU int menu (void){ textcolor(YELLOW); printf("\n\t\t\t:::::::::::FIRESTORM:::::::::::::"); printf("\n________________________________________________________________________________"); textcolor(LIGHT_CYAN); printf("\n"); printf("\n"); printf("\n\t\t <<<<<<<<MENU DE CADASTRO>>>>>>>>"); printf("\n"); printf("\n\t\t [ 1 ] - ADICIONAR UM NOVO CADASTRO "); printf("\n\t\t [ 2 ] - PESQUISAR CADASTROS "); printf("\n\t\t [ 3 ] - SAIR "); printf("\n"); printf("\n"); printf(" "" ] - DIGITE A OPCAO DESEJADA " );printf("\r");printf(" [ ");printf(""); scanf("%d",&op); system ("cls"); return (op); } //FUNCAO DO CADASTRO //------------------------------------------------------------------------------ int cadastro(){ textcolor(YELLOW); printf("\t\t\t\n\t\t\t:::::::::::FIRESTORM::::::::::::: "); printf("\n________________________________________________________________________________"); textcolor(LIGHT_CYAN); for (cont=0;cont<3;cont++){ cont+1; printf("\n\n\n\t\t\t ADICIONANDO REGISTRO.. "); printf("\n\n\nCADASTRE O CLIENTE : \n"); printf("\n\n\nNumero de cadastro_____________________ : "); scanf("%d",&dados[cont].numcliente); printf("\nInsira o nome__________________________ : "); scanf("%s",&dados[cont].nome); printf("\nInsira o Endereco______________________ : "); scanf("%s",&dados[cont].end); printf("\nInsira o Telefone______________________ : "); scanf("%s",&dados[cont].fone); printf("\nInsira o Estado civil__________________ : "); scanf("%s",&dados[cont].ecivil); printf("\nInsira o RG :___________________________: "); scanf("%s",&dados[cont].rg); printf("\nInsira o CIC___________________________ : "); scanf("%s",&dados[cont].cic); printf("\nInsira a data de nascimento____________ : "); scanf("%s",&dados[cont].data); printf("\nInsira a quantidade de dependentes____ : "); scanf("%s",&dados[cont].dep); printf("\n\t::::::CADASTRO REALIZADO COM SUCESSO::::::"); printf("\n\n"); printf("\n\n"); textcolor(YELLOW); printf("\n DESEJA REALMENTE REALIZAR O CADASTRO?(1-SIM 2-não) - "); scanf("%d",&decisao);textcolor(LIGHT_CYAN); switch (decisao){ case 1 : continue; //system("cls");return cadastro(); case 2 : system("cls");return menu(); default:textcolor(LIGHT_RED); printf("\n \t O P C A O I N V A L I D A (VOLTANDO AO MENU PRINCIPAL...) ");textcolor(LIGHT_CYAN);getch(); system("cls");return menu(); } } system("cls"); return(0); } //FUNCAO DE PESQUISA //------------------------------------------------------------------------------ int pesquisa (){textcolor(YELLOW); printf("\n\t\t\t::::::PESQUISA DE CLIENTES:::::: "); printf("\n________________________________________________________________________________"); textcolor(LIGHT_CYAN); printf("\n\n"); printf(" "" ] - DIGITE O NUMERO DE CADASTRO " );printf("\r");printf(" [ ");printf(""); scanf("%d",&ch); pesq = 0; for (cont=0;cont<3;cont++){ if(ch==*dados[cont].numcliente){ printf("\n CADASTRO ENCONTRADO : \n "); printf("\n"); //EXIBIÇÃO DOS DADOS PESQUISADOS printf("\n\tCADASTRO No. %d",*dados[cont].numcliente); printf("\n________________________________"); printf("\n"); printf("\n\t NOME_________________- %s", dados[cont].nome); printf("\n\t ENDERECO_____________- %s", dados[cont].end); printf("\n\t TEL:_________________- %s", dados[cont].fone); printf("\n\t ESTADO CIVIL_________- %s", dados[cont].ecivil); printf("\n\t RG___________________- %s", dados[cont].rg); printf("\n\t CIC__________________- %s", dados[cont].cic); printf("\n\t DATA DE NASCIMENTO___- %s", dados[cont].data); printf("\n\t NUMERO DEPENDENTES___- %s", dados[cont].dep); printf("\n"); pesq =1; return(0); } } if (pesq==0){textcolor(LIGHT_RED); printf("\n\n\t\tCADASTRO não ENCONTRADO, TENTE NOVAMENTE...\n\n\n"); getch(); system("cls"); menu(); } } //TELA PRINCIPAL //------------------------------------------------------------------------------ int main (){ {textcolor(LIGHT_CYAN); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");textcolor(YELLOW); printf("\n\t ##### ## ###### ##### ####### ####### #### ####"); printf("\n\t ##### ## ## ## ### ## ###### ## ## #### ####"); printf("\n\t ## ## ## ## ## ## ####### # # ## ## ## ## ## ## "); printf("\n\t##### ## ###### ##### ####### ## ## ## ###### ## ## ##"); printf("\n\t## ## ## ## #### ## ## ## ## ## ## ## ##"); printf("\n\t## ## ## ## ## ## ## ## ## ## ## ## ##"); printf("\n\t## ## ## # ##### ####### ## ######## ## ## ## ## TM*"); printf("\n\n\n\n\t\t F I R E S T O R M* S/A @ \n\t\t\t\t\t\t\tSolucoes pra você.\n");textcolor(LIGHT_CYAN); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); //printf("GRUPO: David Mauricio; Bianca Ferraz; Michel Lima; Angelli Nascimento"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); textcolor(WHITE); printf("Press ENTER...");textcolor(LIGHT_CYAN); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); } getch(); system("cls"); decisao=0; opcao=menu(); //CHAMANDO AS FUNÇOES //------------------------------------------------------------------------------ while(op!=3){ if (op==1){ cadastro(); opcao=menu(); // while (cont==3) if(cont==3){ textcolor(LIGHT_RED); printf("AGENDA LOTADA");} menu(); opcao=menu(); } if (op==2){ pesquisa(); opcao=menu(); } if (op==3){ printf("\n\n\t\t\t\n\n\n\nSAINDO DO PROGRAMA...\n\n\n\n\n\n\n\n"); } if(op>3) {textcolor(LIGHT_RED); printf("\t\t\tESCOLHA UMA OPCAO VALIDA"); opcao=menu();} } printf("XAU !!!"); getch(); return(0); }Editado por Jonathan QueirozAdcionar tag's (Jonathan)
Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.