Título: ayuda con este menu Publicado por: shadowl9411 en 11 Marzo 2019, 03:03 am buenas estoy empesando y neseito ayuda al imprimir el genoro solo manda numeros no imprime el nombre y en mi numero siempre muestra el mismo tambien tengo que validar si el numero ya se encuentra registrado desde el registro.
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> void mostrar_menu() { int i; system("color 02"); system("pause"); system("cls"); system("color 07"); printf("\n\nMenú:\n=====\n\n"); printf("Escoge una opción:\n "); char a [][60]={"","|***Añadir***|","|****Mostrar****|","|*****Eliminar cliente*****|","|*****Salir*****|"}; for(i=1;i<5;i++){ printf("%d-%s\n",i,a); } } struct registro{ int numero; char nombre[30]; char genero[20]; float paga; }; struct registro emp; FILE *fd; void anadir() { char otro; fd=fopen("cliente.txt","a"); if(fd==NULL) { printf("El archivo no se puede abrir ....\n\t\t\t"); system("pause"); } else { do{ system("cls");; printf("\t\t\tREGISTRAR \n"); printf("\n\t\tNumero : "); scanf("%d",&emp.numero); fflush(stdin); printf("\t\tNombre : "); gets(emp.nombre); fflush(stdin); printf("\t\tGenero: "); gets(emp.genero); fflush(stdin); printf("\t\tPaga $"); scanf("%f",&emp.paga); fflush(stdin); fprintf(fd,"%d %s %f \n",emp.numero,emp.nombre,emp.paga); printf("\n\t\tDesea registrar otro S/N :"); scanf("%s",&otro); }while ( otro =='S' || otro =='s' ) ; fclose(fd); } } void mostrar_lista(){ system("cls"); fd=fopen("cliente.txt","r"); if(fd==NULL) { printf("\t\tEl archivo no se puede abrir ....\n\t\t\t"); system("pause"); } else { printf("\t\t R E P O R T E D E C L I E N T E S "); printf("\n\n\t\tNumero \tNombre \tGenero \t Paga \n"); printf("\t\t______ \t______ \t _____ \t _____ \n"); fscanf(fd,"%d",&emp.numero); while (! feof(fd)) { fscanf(fd,"%s",&emp.nombre); fscanf(fd,"%s",&emp.genero); fscanf(fd,"%f",&emp.paga); printf("\t\t%d\t%s\t%s\t$%.2f \n",emp.numero, emp.nombre , emp.genero ,emp.paga); fscanf(fd,"%d",&emp.numero); } printf("\n\t\t"); system("pause"); } } void elimina_lista(){ int buscar; FILE *aux; int bandera=0; system("cls"); printf("\t\tELIMINAR CLIENTE\n "); printf("\t\tNumero de cliente : "); scanf("%d",&buscar); fd=fopen("cliente.txt","r"); aux=fopen("auxiliar.txt","w"); if(fd==NULL) { printf("\n El archivo no se puede abrir, primero debe crearlo"); system("pause"); } else { bandera=0; fscanf(fd,"%d",&emp.numero); while (!feof(fd) ) { fscanf(fd,"%s",&emp.nombre); fscanf(fd,"%s",&emp.genero); fscanf(fd,"%f",&emp.paga); if( buscar== emp.numero) { printf("\t\tNombre %s\n",emp.nombre); printf("\t\tGenero %s\n",emp.genero); printf("\t\tPaga $%f\n",emp.paga); printf(" \n\t\tEl cliente sera eliminado y no lo recuperara.....\n\t\t"); system("pause"); bandera=1; } else { fprintf(aux,"%d %s %s %f\n",emp.numero, emp.nombre, emp.genero, emp.paga); } fscanf(fd,"%d",&emp.numero); } if (bandera==0){ printf("\nEl cliente no existe\n"); } fclose(fd); fclose(aux); remove("cliente.txt"); rename("auxiliar.txt","cliente.txt"); } } int main () { int opc, x=0, num, z; do { mostrar_menu(); opc = getch(); switch ( opc ) { case '1': anadir(); break; case '2': printf("Lista de clientes\n"); mostrar_lista(emp); fclose(fd); break; case '3':printf("Eliminar registro \n"); elimina_lista(); break; case '4': exit( 1 ); break; default: printf( "Opcion no valida\n" ); break; } } while (opc!='4'); return 0; } Título: Re: ayuda con este menu Publicado por: digimikeh en 11 Marzo 2019, 03:22 am Amigo, le dejo aquí su código formateado para que lo ayuden mejor..
Código
Título: Re: ayuda con este menu Publicado por: Marioxx en 11 Marzo 2019, 04:58 am Buenas noches! El menú tiene que estar a-juro dentro de una función??
|