elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  ayuda con este menu
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ayuda con este menu  (Leído 1,684 veces)
shadowl9411

Desconectado Desconectado

Mensajes: 1


Ver Perfil
ayuda con este menu
« 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;

 }


En línea

digimikeh

Desconectado Desconectado

Mensajes: 191


Ver Perfil
Re: ayuda con este menu
« Respuesta #1 en: 11 Marzo 2019, 03:22 am »

Amigo, le dejo aquí su código formateado para que lo ayuden mejor..

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. void mostrar_menu() {
  7.     int i;
  8. system("color 02");
  9. system("pause");
  10. system("cls");
  11. system("color 07");
  12.      printf("\n\nMenú:\n=====\n\n");
  13.      printf("Escoge una opción:\n ");
  14.      char a [][60]={"","|***Añadir***|","|****Mostrar****|","|*****Eliminar cliente*****|","|*****Salir*****|"};
  15.  
  16.  for(i=1;i<5;i++){
  17.  printf("%d-%s\n",i,a);
  18. }
  19. }
  20.  
  21.  
  22. struct registro{
  23. int numero;
  24. char   nombre[30];
  25. char   genero[20];
  26. float paga;
  27. };
  28. struct registro emp;
  29.  
  30. FILE *fd;
  31.  
  32. void anadir()
  33. {
  34.    char otro;
  35.    fd=fopen("cliente.txt","a");
  36.   if(fd==NULL)
  37.   {
  38.      printf("El archivo no se puede abrir ....\n\t\t\t");
  39.      system("pause");
  40.   }
  41.   else
  42.   {
  43.       do{
  44.            system("cls");;
  45.            printf("\t\t\tREGISTRAR  \n");
  46.            printf("\n\t\tNumero  : ");   scanf("%d",&emp.numero);   fflush(stdin);
  47.            printf("\t\tNombre  : ");   gets(emp.nombre);          fflush(stdin);
  48.            printf("\t\tGenero: ");   gets(emp.genero);          fflush(stdin);
  49.            printf("\t\tPaga  $");    scanf("%f",&emp.paga);   fflush(stdin);
  50.            fprintf(fd,"%d  %s %f \n",emp.numero,emp.nombre,emp.paga);
  51.            printf("\n\t\tDesea registrar otro S/N :");
  52.            scanf("%s",&otro);
  53.       }while ( otro =='S' ||  otro =='s' ) ;
  54.        fclose(fd);
  55.     }
  56. }
  57. void mostrar_lista(){
  58.     system("cls");
  59.    fd=fopen("cliente.txt","r");
  60.    if(fd==NULL)
  61.    {
  62.      printf("\t\tEl archivo no se puede abrir ....\n\t\t\t");
  63.      system("pause");
  64.    }
  65.    else
  66.    {
  67.        printf("\t\t     R E P O R T E    D E    C L I E N T E S  ");
  68.        printf("\n\n\t\tNumero \tNombre \tGenero \t Paga \n");
  69.        printf("\t\t______ \t______ \t _____ \t _____ \n");
  70.        fscanf(fd,"%d",&emp.numero);
  71.        while (! feof(fd))
  72.        {
  73.           fscanf(fd,"%s",&emp.nombre);
  74.           fscanf(fd,"%s",&emp.genero);
  75.           fscanf(fd,"%f",&emp.paga);
  76.           printf("\t\t%d\t%s\t%s\t$%.2f \n",emp.numero, emp.nombre , emp.genero ,emp.paga);
  77.           fscanf(fd,"%d",&emp.numero);
  78.        }
  79.        printf("\n\t\t");
  80.        system("pause");
  81.    }
  82. }
  83.  
  84. void elimina_lista(){
  85.    int buscar;
  86.    FILE *aux;
  87.    int bandera=0;
  88.       system("cls");
  89.       printf("\t\tELIMINAR CLIENTE\n  ");
  90.       printf("\t\tNumero de cliente : ");
  91.       scanf("%d",&buscar);
  92.       fd=fopen("cliente.txt","r");
  93.       aux=fopen("auxiliar.txt","w");
  94.       if(fd==NULL)
  95.        {
  96.          printf("\n       El archivo no se puede abrir, primero debe crearlo");
  97.          system("pause");
  98.         }
  99.         else
  100.         {
  101.            bandera=0;
  102.             fscanf(fd,"%d",&emp.numero);
  103.            while (!feof(fd) )
  104.            {
  105.                  fscanf(fd,"%s",&emp.nombre);
  106.                  fscanf(fd,"%s",&emp.genero);
  107.                  fscanf(fd,"%f",&emp.paga);
  108.                  if( buscar== emp.numero)
  109.                  {
  110.                    printf("\t\tNombre              %s\n",emp.nombre);
  111.                    printf("\t\tGenero              %s\n",emp.genero);
  112.                    printf("\t\tPaga             $%f\n",emp.paga);
  113.                    printf(" \n\t\tEl cliente sera eliminado y no lo recuperara.....\n\t\t");
  114.                    system("pause");
  115.                    bandera=1;
  116.                  }
  117.                  else
  118.                  {
  119.                    fprintf(aux,"%d %s %s %f\n",emp.numero, emp.nombre, emp.genero, emp.paga);
  120.                  }
  121.                  fscanf(fd,"%d",&emp.numero);
  122.  
  123.            }
  124.            if (bandera==0){
  125.                    printf("\nEl cliente no existe\n");
  126.            }
  127.            fclose(fd);
  128.            fclose(aux);
  129.            remove("cliente.txt");
  130.            rename("auxiliar.txt","cliente.txt");
  131.         }
  132.  
  133. }
  134.  
  135.  
  136.  
  137. int main () {
  138.     int opc,  x=0, num, z;
  139.     do {
  140.         mostrar_menu();
  141.         opc = getch();
  142.             switch ( opc ) {
  143.                case '1': anadir();
  144.                       break;
  145.                case '2':  printf("Lista de clientes\n");
  146.                mostrar_lista(emp);
  147.                     fclose(fd);
  148.  
  149.                        break;
  150.                case '3':printf("Eliminar registro \n");
  151.                  elimina_lista();
  152.                        break;
  153.                case '4': exit( 1 ); break;
  154.                default: printf( "Opcion no valida\n" );
  155.                         break;
  156.             }
  157.     } while (opc!='4');
  158.  
  159.     return 0;
  160.  
  161. }
  162.  


En línea

Dungeons & dragons;
dragons.Attack();
Marioxx

Desconectado Desconectado

Mensajes: 3


Ver Perfil
Re: ayuda con este menu
« Respuesta #2 en: 11 Marzo 2019, 04:58 am »

Buenas noches! El menú tiene que estar a-juro dentro de una función?? 
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Como puedo arreglar este menu en flash?
Diseño Gráfico
coolfrog 2 2,549 Último mensaje 5 Septiembre 2007, 15:27 pm
por _loko_
[MOD] se puede hacer este menu de dvd?
Multimedia
M-a-t-d 0 1,789 Último mensaje 20 Septiembre 2007, 20:28 pm
por M-a-t-d
En Que esta echo este menu...
Desarrollo Web
poncho_gc 4 3,045 Último mensaje 31 Julio 2013, 03:52 am
por 1mpuls0
Ayuda en Python! Hacer un menú dentro de otro menú con diccionarios
Scripting
Daor02 1 3,738 Último mensaje 3 Julio 2016, 05:28 am
por tincopasan
Hacer un menú sencillo con este Script
Scripting
Meta 4 3,343 Último mensaje 22 Noviembre 2017, 14:20 pm
por Meta
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines