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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


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

Desconectado Desconectado

Mensajes: 8


Ver Perfil
Error al compilar
« en: 25 Octubre 2012, 18:15 pm »

Q tal amigos miren ttengo este error al compilar este codigo

Código
  1. struct sEstado_1 {
  2.   char Nombre[40];
  3.   int Codigo;
  4.   char Estado[10];
  5. } E1;
  6.  
  7. struct sDatos_1 {
  8.   float Materia1;
  9.   float Materia2;
  10.   float Materia3;
  11.   float Materia4;
  12.   float Materia5;
  13.   float Materia6;
  14.   float Materia7;  
  15. } D1;
  16.  
  17.  
  18. void Buscar (){    
  19.  
  20.    FILE *Estado1;
  21.    int clave;
  22.    printf("Digite El Codigo Del Estudiante Q quiere Buscar: ");
  23.    scanf("%d", clave);
  24.     Estado1 = fopen("fichero.txt", "r");
  25.  
  26.        if(Estado1 == NULL)
  27.        {
  28.                printf("\nFichero no existe! \nPor favor creelo");
  29.                return;
  30.        }
  31.  
  32.  
  33. while(fread(&E1, sizeof(struct sEstado_1), 1, Estado1)==1)
  34. {
  35. // desplegando estructura buscada
  36. if ( clave == E1.Codigo)
  37. {
  38. printf("CODIGO =%d ",E1.Codigo);
  39. printf(" NOMBRE =%s ",E1.Nombre);
  40. printf(" ESTADO =%d ",E1.Estado);
  41. printf("\n");
  42. }// fin if
  43. }//fin while
  44.  
  45. fclose(Estado1);
  46.  
  47. }
  48.  
al insertar "clave" me sale que el programa dejo de funcionar

Codigo completo

Código
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <cstdlib>
  6. #include <windows.h>
  7.  
  8. using namespace std;
  9.  
  10. void menu();
  11. void CrearFichero(FILE *Estado1);
  12. void InsertarDatos(FILE *Estado1);
  13. void VerDatos(FILE *Estado1);
  14. void CrearArchivo(FILE *Datos1);
  15. void InsertarArchivos(FILE *Datos1);
  16. void VerArchivos(FILE *Datos1);
  17.  
  18.  
  19. struct sEstado_1 {
  20.   char Nombre[40];
  21.   int Codigo;
  22.   char Estado[10];
  23. } E1;
  24.  
  25. struct sDatos_1 {
  26.   float Materia1;
  27.   float Materia2;
  28.   float Materia3;
  29.   float Materia4;
  30.   float Materia5;
  31.   float Materia6;
  32.   float Materia7;  
  33. } D1;
  34.  
  35.  
  36. void Buscar (){    
  37.  
  38.    FILE *Estado1;
  39.    int clave;
  40.    printf("Digite El Codigo Del Estudiante Q quiere Buscar: ");
  41.    scanf("%d", clave);
  42.     Estado1 = fopen("fichero.txt", "r");
  43.  
  44.        if(Estado1 == NULL)
  45.        {
  46.                printf("\nFichero no existe! \nPor favor creelo");
  47.                return;
  48.        }
  49.  
  50.  
  51. while(fread(&E1, sizeof(struct sEstado_1), 1, Estado1)==1)
  52. {
  53. // desplegando estructura buscada
  54. if ( clave == E1.Codigo)
  55. {
  56. printf("CODIGO =%d ",E1.Codigo);
  57. printf(" NOMBRE =%s ",E1.Nombre);
  58. printf(" ESTADO =%d ",E1.Estado);
  59. printf("\n");
  60. }// fin if
  61. }//fin while
  62.  
  63. fclose(Estado1);
  64.  
  65. }
  66.  
  67. void PlanEstudio ()
  68. {
  69.        int opcion4;
  70.        FILE *Estado1;
  71.        FILE *Datos1;
  72.        int exit = 0;
  73.  
  74.        printf("\n   *** PLAN DE ESTUDIOS ***\n");
  75.        printf("\n\t1. Conultar Materias 1º Semestre");
  76.        printf("\n\t2. Conultar Materias 2º Semestre");
  77.        printf("\n\t3. Conultar Materias 3º Semestre");
  78.        printf("\n\t4. Conultar Materias 4º Semestre");
  79.        printf("\n\t5. Conultar Materias 5º Semestre");
  80.        printf("\n\t6. Conultar Materias 6º Semestre");
  81.        printf("\n\t7. Salir");
  82.  
  83.        while (!exit)
  84.        {
  85.                printf("\nOpcion: ");
  86.                scanf("%d", &opcion4);
  87.  
  88.                switch(opcion4)
  89.                {
  90.                        case 1:
  91.  
  92.                        break;        
  93.                        case 2:
  94.  
  95.                        break;        
  96.                        case 3:
  97.  
  98.                        break;        
  99.                        case 4:
  100.  
  101.                        break;        
  102.                        case 5:
  103.  
  104.                        break;
  105.                        case 6:
  106.  
  107.                        break;
  108.                        case 7:
  109.                                exit = 1;
  110.                        break;    
  111.                        default:
  112.                                printf("\n ** Esta opcion no es valida **\n");      
  113.                }
  114.        }
  115.  
  116.        return ;            
  117. }
  118.  
  119. void menuBusqueda()
  120. {
  121.        int opcion3;
  122.        FILE *Estado1;
  123.        FILE *Datos1;
  124.        int exit = 0;
  125.        printf("\n   *** MENU DE BUSQUEDA ***\n");
  126.        printf("\n\t1. Conultar Lista De Estudiantes");// lista
  127.        printf("\n\t2. Estado Del Estudiante");// datos: direccion, tel, etc...
  128.        printf("\n\t3. Plan De Estudio");// plan proyecto curricular
  129.        printf("\n\t4. Consultar Estudiante");// materias
  130.        printf("\n\t5. Volver al inicio");
  131.        printf("\n\t6. Salir");      
  132.  
  133.         while (!exit)
  134.        {
  135.                printf("\nOpcion: ");
  136.                scanf("%d", &opcion3);
  137.  
  138.                switch(opcion3)
  139.                {
  140.                        case 1:
  141.                               VerDatos(Estado1);
  142.                        break;        
  143.                        case 2:
  144.                               cout <<"Estado Del Estudiante";
  145.                        break;        
  146.                        case 3:
  147.                                PlanEstudio();
  148.                        break;        
  149.                        case 4:
  150.                                Buscar();
  151.                        break;        
  152.                        case 5:
  153.                                menu();
  154.                        break;
  155.                        case 6:
  156.                                exit = 1;
  157.                        break;
  158.                        default:
  159.                                printf("\n ** Esta opcion no es valida **\n");      
  160.                }
  161.        }
  162.  
  163.        return;
  164. }
  165.  
  166. void menuLista(){
  167.        int opcion2;
  168.        FILE *Estado1;
  169.        FILE *Datos1;
  170.        int exit = 0;
  171.     printf("\n   *** MENU LISTA ***\n");      
  172.        printf("\n\t1. Crear Archivo Lista");
  173.        printf("\n\t2. Insertar Datos a Lista");
  174.        printf("\n\t3. Ver Datos Lista");
  175.        printf("\n\t4. Volver Al Inicio");
  176.        printf("\n\t5. Salir Del Programa");
  177.        while (!exit)
  178.        {
  179.                printf("\nOpcion: ");
  180.                scanf("%d", &opcion2);
  181.  
  182.                switch(opcion2)
  183.                {
  184.                        case 1:
  185.                                CrearArchivo(Datos1);
  186.                        break;        
  187.                        case 2:
  188.                                InsertarArchivos(Datos1);
  189.                        break;        
  190.                        case 3:
  191.                                VerArchivos(Datos1);
  192.                        break;        
  193.                        case 4:
  194.                                menu();
  195.                        break;        
  196.                        case 5:
  197.                                exit = 1;
  198.                        break;
  199.                        default:
  200.                                printf("\nOpcion no valida");      
  201.                }
  202.        }
  203.  
  204.        return;
  205.     }
  206.  
  207. void menuAdministrativo()
  208. {
  209.        int opcion2;
  210.        FILE *Estado1;
  211.        FILE *Datos1;
  212.        int exit = 0;
  213.  
  214.        printf("\n   *** MENU ADMIISTRATIVO ***\n");      
  215.        printf("\n\t1. Crear Fichero");
  216.        printf("\n\t2. Insertar Datos");
  217.        printf("\n\t3. Ver Datos Parciales");
  218.        printf("\n\t4. Volver Al Inicio");
  219.        printf("\n\t5. Salir Del Programa");
  220.        while (!exit)
  221.        {
  222.                printf("\nOpcion: ");
  223.                scanf("%d", &opcion2);
  224.  
  225.                switch(opcion2)
  226.                {
  227.                        case 1:
  228.                                CrearFichero(Estado1);
  229.                        break;        
  230.                        case 2:
  231.                                InsertarDatos(Estado1);
  232.                        break;        
  233.                        case 3:
  234.                                VerDatos(Estado1);
  235.                        break;        
  236.                        case 4:
  237.                                menu();
  238.                        break;        
  239.                        case 5:
  240.                                exit = 1;
  241.                        break;
  242.                        default:
  243.                                printf("\nOpcion no valida");      
  244.                }
  245.        }
  246.  
  247.        return;
  248.  
  249. }
  250. void menu()
  251. {
  252.     int opcion, exit=0;
  253.  
  254.        printf("\n           *** MENU PRINCIPAL ***\n ");
  255.        printf("\n\t1. Ir al Menu Administrativo ");
  256.        printf("\n\t2. Ir al Menu De Busqueda ");
  257.        printf("\n\t3. Ir al Menu Lista");
  258.        printf("\n\t4. Salir");
  259.  
  260.        while (!exit)
  261.        {
  262.                printf("\n\nOpcion: ");
  263.                scanf("%d", &opcion);
  264.  
  265.                switch(opcion)
  266.                {
  267.  
  268.                        case 1:
  269.                                system("CLS");
  270.                                menuAdministrativo();              
  271.                        case 2:
  272.                                system("CLS");
  273.                                menuBusqueda();
  274.                        case 3:
  275.                                system("CLS");
  276.                                menuLista();
  277.                        case 4:
  278.                                system("CLS");
  279.                                exit = 1;
  280.                        break;
  281.                        default:
  282.                                printf("\nOpcion no valida");
  283.                }
  284.        }
  285.  
  286.        return ;
  287.  
  288. }
  289. int main ()
  290. {
  291.        system("color f");
  292.  
  293.        int opcion, opcion2, opcion3, opcion4;
  294.        int exit = 0;
  295.        FILE *Estado1;
  296.        FILE *Datos1;          
  297.        menu();
  298. }
  299.  
  300. void CrearFichero(FILE *Estado1)
  301. {
  302.        Estado1 = fopen("fichero.txt", "r");
  303.  
  304.        if(!Estado1)
  305.        {
  306.                Estado1 = fopen("fichero.txt", "w");
  307.                printf("\nArchivo creado!");
  308.        }
  309.        else
  310.        {
  311.                printf("\nEl fichero ya existe!");
  312.        }
  313.  
  314.        fclose (Estado1);
  315.  
  316.        return;
  317. }
  318. void InsertarDatos(FILE *Estado1)
  319. {
  320.        Estado1 = fopen("fichero.txt", "a+");
  321.  
  322.        if(Estado1 == NULL)
  323.        {
  324.                printf("\nFichero no existe! \nPor favor creelo");
  325.                return;
  326.        }
  327.  
  328. for (int a=1; a<=4; a++){
  329.        printf("\nDigita el Nombre: ");
  330.        scanf("%s", &E1.Nombre);
  331.  
  332.        printf("\nDigita el Codigo: ");
  333.        scanf("%d", &E1.Codigo);
  334.  
  335.        printf("\nEstado Del Estudiante: ");
  336.        scanf("%s", &E1.Estado);
  337.  
  338.        fwrite(&E1, sizeof(struct sEstado_1), 1, Estado1);
  339.   }
  340.        fclose(Estado1);
  341.  
  342.        return;
  343. }
  344. void VerDatos(FILE *Estado1)
  345. {
  346.        int numero = 1;
  347.  
  348.        Estado1 = fopen("fichero.txt", "r");
  349.  
  350.        if(Estado1 == NULL)
  351.        {
  352.                printf("\nFichero no existe! \nPor favor creelo");
  353.                return;
  354.        }
  355.  
  356.        fread(&E1, sizeof(struct sEstado_1), 1, Estado1);
  357.        printf("\nNumero \tNombre        \tCodigo     \tEstado Del Estudiate");
  358.  
  359.        while(!feof(Estado1))
  360.        {
  361.                printf("\n%d \t%s        \t%d        \t%s", numero, E1.Nombre, E1.Codigo, E1.Estado);
  362.                fread(&E1, sizeof(struct sEstado_1), 1, Estado1);
  363.                numero++;
  364.        }
  365.  
  366.        fclose(Estado1);
  367.  
  368.        return;
  369. }
  370. void CrearArchivo(FILE *Datos1)
  371. {
  372.        Datos1 = fopen("datos.txt", "r");
  373.  
  374.        if(!Datos1)
  375.        {
  376.                Datos1 = fopen("fichero.txt", "w");
  377.                printf("\nArchivo creado!");
  378.        }
  379.        else
  380.        {
  381.                printf("\nEl fichero ya existe!");
  382.        }
  383.  
  384.        fclose (Datos1);
  385.  
  386.        return;
  387. }
  388.  
  389. void InsertarArchivos(FILE *Datos1)
  390. {
  391.        Datos1 = fopen("datos.txt", "a+");
  392.  
  393.        if(Datos1 == NULL)
  394.        {
  395.                printf("\nFichero no existe! \nPor favor creelo");
  396.                return;
  397.        }
  398.  
  399.        printf("\nDigite la nota de Algoritmos: ");
  400.        scanf("%f", &D1.Materia1);
  401.  
  402.        printf("\nDigite la nota de Calculo: ");
  403.        scanf("%f", &D1.Materia2);
  404.  
  405.        printf("\nDigite la nota de Catedra FJDC: ");
  406.        scanf("%f", &D1.Materia3);
  407.  
  408.        printf("\nDigite la nota de Catedra DYC: ");
  409.        scanf("%f", &D1.Materia4);
  410.  
  411.        printf("\nDigite la nota de Logica: ");
  412.        scanf("%f", &D1.Materia5);
  413.  
  414.        printf("\nDigite la nota de Algebra: ");
  415.        scanf("%f", &D1.Materia6);
  416.  
  417.        printf("\nDigite la nota de Textos: ");
  418.        scanf("%f", &D1.Materia7);
  419.  
  420.        fwrite(&D1, sizeof(struct sDatos_1), 1, Datos1);
  421.  
  422.        fclose(Datos1);
  423.  
  424.        return;
  425. }
  426.  
  427. void VerArchivos(FILE *Datos1)
  428. {
  429.        int numero = 1;
  430.  
  431.        Datos1 = fopen("datos.txt", "r");
  432.  
  433.        if(Datos1 == NULL)
  434.        {
  435.                printf("\nFichero no existe! \nPor favor creelo");
  436.                return;
  437.        }
  438.  
  439.        fread(&D1, sizeof(struct sDatos_1), 1, Datos1);
  440.  
  441.        printf("\nNumero \tAlgoritmos \tCalculo \tCatedra FJDC \tCatedra DYC \tLogica \tAlgebra \tTextos");
  442.  
  443.        while(!feof(Datos1))
  444.        {
  445.                printf("\n%d \t%f \t%f \t%f \t%f \t%f \t%f \t%f", numero, D1.Materia1, D1.Materia2, D1.Materia3,
  446.                D1.Materia4, D1.Materia5, D1.Materia6, D1.Materia7);
  447.                fread(&D1, sizeof(struct sDatos_1), 1, Datos1);
  448.                numero++;
  449.        }
  450.  
  451.        fclose(Datos1);
  452.  
  453.  
  454.        return;
  455. }
  456.  


En línea

Caster


Desconectado Desconectado

Mensajes: 786


Ver Perfil WWW
Re: Error al compilar
« Respuesta #1 en: 25 Octubre 2012, 18:24 pm »

Porque en esta linea:

Código
  1. scanf("%d", clave);

Te falta el amperstand (&) antes de clave, seria asi:

Código
  1. scanf("%d", &clave);

No revise el resto del codigo, pero en principio es ese el fallo, revisa todo a ver si se te paso ponerlo en algun scanf mas

Saludos


En línea

estivinho

Desconectado Desconectado

Mensajes: 8


Ver Perfil
Re: Error al compilar
« Respuesta #2 en: 25 Octubre 2012, 18:46 pm »

Jajaja Q loco amigo Muchas gracias modifique el codigo de 1000 formas y nunca me fique en esto :) ;-) ;-) ;-) ;-)
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Error al compilar
Programación Visual Basic
newbY 2 1,789 Último mensaje 9 Noviembre 2007, 13:40 pm
por newbY
me da error al compilar
Programación Visual Basic
elguast 2 1,775 Último mensaje 29 Junio 2008, 11:54 am
por elguast
Error al compilar un BAT a EXE « 1 2 »
Scripting
xXEsEtUlOnXx 10 7,603 Último mensaje 26 Julio 2008, 02:19 am
por morenochico
Error al compilar
ASM
Kerber0 4 7,213 Último mensaje 7 Enero 2010, 09:58 am
por Eternal Idol
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines