Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. int main()
  2. {char p_testo[201], p_cript[201], p_sost[201];
  3. int j=0, i=0, indice=0, k=0;
  4. FILE *text, *diz, *mex;
  5. text=fopen("sorgente.txt","r");
  6. if(text==NULL){
  7. printf("errore nell'apertura della sorgente");
  8. return -1;}
  9.  
  10. mex=fopen("ricodificato.txt","w");
  11. if(mex==NULL){
  12. printf("errore nell'apertura del messaggio ricodificato");
  13. return -3;}
  14. while(text!=EOF){
  15. diz=fopen("dizionario.txt","r");
  16. if(diz==NULL){
  17. printf("errore nell'apertura del dizionario");
  18. return -2;}
  19. fscanf(text,"%s", p_testo);
  20. while(diz!=EOF){
  21. fscanf(diz,"%s %s", p_cript, p_sost);
  22. for(j=0;j<strlen(p_testo);j++){
  23. if(p_sost[i]==p_testo[j]){
  24. indice=j;//verifico le parole
  25. for(i=0;i<strlen(p_sost)&&p_sost[i]==p_testo[j];i++)
  26. j++;}
  27. }
  28. if(i==strlen(p_sost)){//srivo il messaggio con le parole cambiate
  29. for(k=0;k<indice;k++)
  30. fprintf(mex,"%c", p_testo[k]);
  31. for(k=0;k<strlen(p_cript);k++)
  32. fprintf(mex,"%c", p_cript[k]);
  33. for(k=strlen(p_sost)+indice;k<strlen(p_testo)-strlen(p_sost)-indice;k++)
  34. fprintf(mex,"%c", p_testo[k]);
  35. fprintf(mex," ");
  36. i=0;
  37. break;}
  38. }
  39. if(i==strlen(p_testo)){//scrivo la parola normale perchè non ho trovato la sostituzione
  40. fprintf(mex,"%s", p_testo);
  41. fprintf(mex," ");
  42. j=0;}
  43. fclose(diz);
  44. }
  45. fclose(mex);
  46. fclose(text);
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement