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

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / codigo en c errores en: 11 Diciembre 2020, 23:24 pm
no puedo compilarlo, creo que el error esta en el carga con los punteros, pero nose como arreglarlo

Código
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define N 10000
  4.  
  5. typedef struct traductor{
  6.    char espanol[20];
  7.    char ingles[20];
  8.    int num;
  9.  }traductor;
  10. traductor T[N];
  11. traductor Auxi;
  12.  
  13.  
  14. void CARGA(struct traductor T[N], int *i){
  15.  
  16.  
  17.    FILE *archivo1=fopen("espaingl.dat","r");
  18.    if(archivo1 == NULL){
  19.        printf("\nError en la apertura del archivo\n");
  20.    return;
  21.    }
  22.    while(!feof(archivo1)){
  23.            fscanf(archivo1,"%s  %s %d",T[*i].espanol, T[*i].ingles, T[*i].num);
  24.            *i=*i+1;
  25.   }
  26.    fclose(archivo1);
  27. }
  28.  
  29. int busqueda_dicotomica (struct traductor T[N], int *i, char pal_espanol[21]) {
  30.    int min, max, medio;
  31.    char palabra;
  32.    min=0;
  33.    max= *i-1;
  34.    medio= (min + max)/2;
  35.    while (strcmp(T[medio].espanol, pal_espanol)!=0 &&min<=max) {
  36.            if (strcmp(pal_espanol, T[medio].espanol) <0){
  37.                max=medio-1;}
  38.            else{
  39.                min=medio+1;}
  40.  
  41.            medio= (min+max)/2; //fin si
  42.    }//fin mientras
  43.    if (strcmp(T[medio].espanol, pal_espanol) ==0)
  44.        return (medio); //se encontro la nueva palabra en el listado
  45.    else
  46.        return -1; //no se encontro la palabra en el listado
  47.    //finsi
  48.  
  49. }//fin busqueda dicotomica
  50.  
  51. int MENU(){
  52.    int op;
  53.    printf("--------------------------\n");
  54.    printf("BIENVENIDO AL TRADUCTOR\n\n");
  55.    printf("Elija la opcion que desee\n");
  56.    printf("(1)Ingles a Espanol\n");
  57.    printf("(2)Espanol a Ingles\n");
  58.    printf("(0)Cerrar");
  59.    printf("\n--------------------------\n");
  60.    printf("Opcion: ");
  61.    scanf("%d", &op);
  62.    while(op<0 || op>2){
  63.        printf("Error- opcion inexistente, elija entre 0 y 2: ");
  64.        scanf("%d", &op);
  65.    }
  66. }
  67.  
  68. int MENU1(){
  69.    char w;
  70.    printf("\nElija opcion\n");
  71.    printf("T - Traducir al espanol\n");
  72.    printf("A - Agregar palabra\n");
  73.    printf("M - Mas buscadas\n");
  74.    printf("V - Volver\n");
  75.    printf("Opcion: ");
  76.    scanf(" %c",&w);
  77.    while(w!='t' && w!='a' && w!='m' && w!='v'){
  78.        printf("Error- Elija T, A, M o V: ");
  79.        scanf(" %c",&w);
  80.    }
  81. }
  82.  
  83. int MENU2(){
  84.    char q;
  85.    printf("\nElija opcion\n");
  86.    printf("T - Traducir al ingles\n");
  87.    printf("A - Agregar palabra\n");
  88.    printf("M - Mas buscadas\n");
  89.    printf("V - Volver\n");
  90.    printf("Opcion: ");
  91.    scanf(" %c",&q);
  92.    while(q!='t' && q!='a' && q!='m' && q!='v'){
  93.        printf("Error- Elija T, A, M o V:");
  94.        scanf(" %c",&q);
  95.    }
  96. }
  97.  
  98. void tradu(int opc, int *i) {
  99.     int p, j, temp,des,band1,band,medio;
  100.     char aux[20], la[20];
  101.  
  102.     CARGA(T, &i);
  103.     temp = 0;
  104.  
  105.     printf ("\nIntroduce la palabra que desea buscar: ");
  106.     fflush(stdin);
  107.     fgets(aux,N,stdin);
  108.     cambio (aux);
  109.     if(opc==1){
  110.        band=0;
  111.        while(band==0){
  112.            for (p=0 ; p<*i; p++) {
  113.                j = strcmp (aux, T[p].ingles);
  114.                if(j==0){
  115.                    printf("La traduccion de %s es %s\n", T[p].ingles, T[p].espanol);
  116.                    T[p].num=T[p].num+1;
  117.  
  118.                    band++;
  119.                }
  120.            }
  121.        }
  122.                if(band!=0){
  123.                    printf("La palabra no se encontro, Si desea agregarla marque 1");
  124.                    scanf(" %d", &des);
  125.                    if(des==1){
  126.                            strcpy(T[*i].ingles, aux);
  127.                            printf("Ingrese la traduccion: ");
  128.                            scanf(" %s", &la);
  129.                            strcpy(T[*i].espanol, la);
  130.                            T[*i].num=0;
  131.                            *i=*i+1;
  132.                    }
  133.                }
  134.     }
  135.     else {
  136.            band1=0;
  137.            while(band1==0){
  138.                    medio=busqueda_dicotomica(T, &i, aux);
  139.                        j = strcmp (aux, T[medio].espanol);
  140.                        if (j == 0) {
  141.                            printf ("La traduccion de %s es %s\n", T[medio].espanol, T[medio].ingles);
  142.                            band1++;
  143.                            T[medio].num=T[medio].num+1;
  144.                        }
  145.  
  146.            }
  147.            if(band!=0){
  148.                printf("La palabra no se encontro, Si desea agregarla marque 1 o cero para volver");
  149.                scanf(" %d", &des);
  150.                if(des==1){
  151.                        strcpy(T[*i].espanol, aux);
  152.                        printf("Ingrese la traduccion: ");
  153.                        scanf(" %s", &la);
  154.                        strcpy(T[*i].ingles, la);
  155.                        T[*i].num=0;
  156.                        *i=*i+1;
  157.                }
  158.            }
  159. }
  160. }
  161.  
  162. void cambio (char palabra[20]) {
  163.    int i;
  164.  
  165.    for(i=0 ; i<N ; i++){
  166.        if (palabra[i] == '\n'){
  167.            palabra[i] = '\0';
  168.        }
  169.    }
  170. }
  171.  
  172. void Agregar (int opc, int *i){
  173.   char Npal, la;
  174.   int p, j,bandera,bandera1,x,c,y,posicion,maximo;
  175.    CARGA (T, &i);
  176.    if (opc ==1){
  177.            printf("Ingrese la palabra que desea agregar");
  178.            scanf (" %s",&Npal );
  179.            bandera==0;
  180.                for(p=0 ; p<*i; p++){
  181.                    j = strcmp (Npal, T[p].ingles);
  182.                    if(j==0){
  183.                        printf("La palabra ya existe");
  184.                        bandera++;
  185.                    }
  186.                }
  187.            if(bandera!=0){
  188.               strcpy(T[*i].ingles, Npal);
  189.                        printf("Ingrese la traduccion: ");
  190.                        scanf(" %s",la);
  191.                        strcpy(T[*i].espanol, la);
  192.                        T[*i].num=0;
  193.                        *i=*i+1;
  194.            }
  195.    }
  196.        if (opc == 2){
  197.            printf("Ingrese la palabra que desea agregar");
  198.            scanf (" %s",&Npal );
  199.            bandera1=0;
  200.            for (c=0 ; c<*i; c++) {
  201.                j = strcmp (Npal, T[c].espanol);
  202.                if(j==0){
  203.                    printf("La palabra ya existe");
  204.                    bandera1++;
  205.                }
  206.            }
  207.                if(bandera1!=0){
  208.                    strcpy(T[*i].ingles, Npal);
  209.                        printf("Ingrese la traduccion: ");
  210.                        scanf(" %s", &la);
  211.                        strcpy(T[*i].ingles, la);
  212.                        T[*i].num=0;
  213.                        *i=*i+1;
  214.                }
  215.            }
  216.            //ordenamiento
  217.  
  218.            for(x=0;x<*i-1;x++){
  219.                maximo= T[x].num;
  220.                posicion=x;
  221.                for(y=x+1;y<*i;y++){
  222.                    if(T[x].num >maximo){
  223.                        maximo=T[x].num;
  224.                        posicion=y;
  225.                    }
  226.                }
  227.              Auxi=T[posicion];
  228.              T[posicion]=T[x];
  229.              T[x]=Auxi;
  230.            }
  231.        }
  232.  
  233. void MasBuscada(int i){
  234.    int x,c,y,posicion,maximo;
  235.    for(x=0;x<i-1;x++){
  236.                maximo= T[x].num;
  237.                posicion=x;
  238.                for(y=x+1;y<i;y++){
  239.                    if(T[x].num >maximo){
  240.                        maximo=T[x].num;
  241.                        posicion=y;
  242.                    }
  243.                }
  244.              Auxi=T[posicion];
  245.              T[posicion]=T[x];
  246.              T[x]=Auxi;
  247.            }
  248.    printf("Las diez palabras mas buscadas fueron: \n");
  249.    for(c=0;c<10;c++){
  250.        printf("%s %s %d \n",T[c].espanol, T[c].ingles, T[c].num );
  251.    }
  252. }
  253.  
  254. int main(void){
  255.    struct traductor T[N];
  256.    int opc,i=0;
  257.    char men1,men2;
  258.  
  259.    CARGA(T,&i);
  260.    opc=MENU();
  261.  
  262.    while(opc!=0){
  263.            switch(opc){
  264.                case 1:
  265.                    printf("Elijio opcion: 1 \n\n");
  266.                    men1=MENU1();
  267.                    while(men1!='v'){
  268.                        switch(men1){
  269.                            case 't':
  270.                                tradu(opc,&i);
  271.                            break;
  272.                            case 'a':
  273.                              Agregar (opc, &i);
  274.                            break;
  275.                            case 'm':
  276.                               MasBuscada(i);
  277.                            break;
  278.                        }
  279.                    men1=MENU1();
  280.                    }
  281.                break;
  282.                case 2:
  283.                    printf("Elijio opcion: 2\n\n");
  284.                    men2=MENU2();
  285.                    while(men2!='v'){
  286.                        switch(men2){
  287.                            case 't':
  288.                                tradu(opc,&i);
  289.                            break;
  290.                            case 'a':
  291.                               Agregar (opc, &i);
  292.                            break;
  293.                            case 'm':
  294.                                MasBuscada(i);
  295.                            break;
  296.                        }
  297.                    men2=MENU2();
  298.                    }
  299.                break;
  300.            }
  301.            opc=MENU();
  302.    }
  303.    printf("\n\nUsted ha finalizado el Programa\n");
  304. return 0;
  305. }


MOD: El código debe estar publicado entre etiquetas de Código GeSHi
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines