Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Luca Santoro:
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- int main(int argc, char *argv[])
- {
- FILE *fp1, *fp2;
- char c,m,p[5+1],t[5+1];
- if(argc!=3)
- {
- fprintf(stderr,"ERRORE ARGOMENTI.\n");
- return -1;
- }
- fp1 = fopen (argv[2],"r");
- if(fp1==NULL)
- {
- fprintf(stderr,"Errore file1.\n");
- return -2;
- }
- /*codice di codifica*/
- if(strcmp(argv[1],'-c')==0)
- {
- while(c=fgetc(fp1)!=EOF)
- { /*apro il file col codice*/
- if(fp2= fopen("morse.txt","r")==NULL)
- {
- fprintf(stderr,"Errore file2.\n");
- return -3;
- }
- /*formatto il file di input*/
- if(isalpha(c))
- {
- c=toupper(c);
- }
- else{c='0';}
- /*stampo la traduzione in morse*/
- while(m=fgetc(fp2) != EOF || c!='0'){
- if(c==m)
- {
- p[0]=fgets(p,5,fp2);
- {
- printf("%s",p);
- printf(" ");
- }
- }
- }
- fclose(fp2);
- }
- }
- if(strcmp(argv[1],'-d')==0)
- {
- while(fscanf(fp1,"%s",t)!=EOF)
- {
- if(fp2= fopen("morse.txt","r")==NULL)
- {
- fprintf(stderr,"Errore file2.\n");
- return -4;
- }
- while(fscanf(fp2,"%c%s",&c,p)!= EOF)
- {
- if(strcmp(t,p)==0)
- {
- printf("%c ",c);
- }
- }
- fclose(fp2);
- }
- }
- fclose(fp1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement