Advertisement
VRonin

Dizionario

Feb 20th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main(){
  7.     FILE* input;
  8.     FILE* output;
  9.     char** inglese;
  10.     char** italiano;
  11.     char riga[1001];
  12.     int index,i,n;
  13.     input=fopen("input.txt","r");
  14.     output=fopen("output.txt","w");
  15.     if(input==NULL || output==NULL)
  16.         printf("Impossibile Leggere il File!");
  17.     fscanf(input,"%d",&n);
  18.     inglese= (char**) malloc(n*sizeof(char*));
  19.     italiano= (char**) malloc(n*sizeof(char*));
  20.     for (i=0;i<n;i++){
  21.         *(inglese+i)=(char*) malloc(101*sizeof(char));
  22.         *(italiano+i)=(char*) malloc(101*sizeof(char));
  23.         fscanf(input,"%s %s",*(inglese+i), *(italiano+i));
  24.     }
  25.     while(fscanf(input,"%s",riga)!=EOF){
  26.             for (i=0;i<n;i++){
  27.                 if (strcmp(riga,*(inglese+i))==0)
  28.                     {index=i; break;}
  29.             }
  30.             fprintf(output,"%s ",*(italiano+index));
  31.     }
  32.     fclose(input);
  33.     fclose (output);
  34.     for (i=0;i<n;i++){
  35.         free(*(inglese+i));
  36.         free(*(italiano+i));
  37.     }
  38.     free(inglese); free(italiano);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement