Advertisement
Guest User

1

a guest
Jan 22nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Luca Santoro:
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. FILE *fp1, *fp2;
  10. char c,m,p[5+1],t[5+1];
  11.  
  12. if(argc!=3)
  13. {
  14. fprintf(stderr,"ERRORE ARGOMENTI.\n");
  15. return -1;
  16.  
  17. }
  18. fp1 = fopen (argv[2],"r");
  19. if(fp1==NULL)
  20. {
  21. fprintf(stderr,"Errore file1.\n");
  22. return -2;
  23. }
  24. /*codice di codifica*/
  25. if(strcmp(argv[1],'-c')==0)
  26. {
  27.  
  28. while(c=fgetc(fp1)!=EOF)
  29. { /*apro il file col codice*/
  30. if(fp2= fopen("morse.txt","r")==NULL)
  31. {
  32. fprintf(stderr,"Errore file2.\n");
  33. return -3;
  34. }
  35. /*formatto il file di input*/
  36. if(isalpha(c))
  37. {
  38. c=toupper(c);
  39.  
  40. }
  41. else{c='0';}
  42. /*stampo la traduzione in morse*/
  43. while(m=fgetc(fp2) != EOF || c!='0'){
  44. if(c==m)
  45. {
  46. p[0]=fgets(p,5,fp2);
  47. {
  48. printf("%s",p);
  49.  
  50. printf(" ");
  51. }
  52.  
  53. }
  54. }
  55. fclose(fp2);
  56. }
  57.  
  58. }
  59.  
  60. if(strcmp(argv[1],'-d')==0)
  61. {
  62. while(fscanf(fp1,"%s",t)!=EOF)
  63. {
  64. if(fp2= fopen("morse.txt","r")==NULL)
  65. {
  66. fprintf(stderr,"Errore file2.\n");
  67. return -4;
  68. }
  69. while(fscanf(fp2,"%c%s",&c,p)!= EOF)
  70. {
  71. if(strcmp(t,p)==0)
  72. {
  73. printf("%c ",c);
  74. }
  75. }
  76. fclose(fp2);
  77. }
  78.  
  79. }
  80. fclose(fp1);
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement