Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Scrivere un programma in C che presi in input due file, denominati fileuno e
- filedue contenenti caratteri minuscoli, copi il contenuto di filedue in coda a
- fileuno, e successivamente crei un nuovo file, il cui nome è inserito
- dall’utente, in cui sia copiato il contenuto di fileuno invertendo le
- minuscole con le maiuscole*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- FILE * check_open_file(char *, char *);
- void check_argument_main(int);
- void append_content(FILE *, FILE *);
- void copy_and_uppecase(FILE*,FILE*);
- int main(int argc, char *argv[]){
- FILE *uno_txt, *due_txt, *tre_txt;
- char file3[30];
- uno_txt=check_open_file("uno.txt","r");
- due_txt=check_open_file("due.txt","a");
- //check_argument_main(argc);
- append_content(uno_txt, due_txt);
- printf("Dammi il nome di un file sul quale copieremo e convertiremo\n"
- "in maiscolo i caratteri copiati : ");
- scanf("%s",file3);
- due_txt=check_open_file("due.txt","r");
- tre_txt=check_open_file(file3,"w");
- printf("%s",file3);
- copy_and_uppecase(due_txt,tre_txt);
- return 0;
- }
- FILE *check_open_file(char *file_name, char *mode){
- FILE *stream;
- stream=fopen(file_name,mode);
- if(stream==NULL){
- printf("Sorry, we have a problem, can't open %s\n", file_name);
- exit(EXIT_FAILURE);
- }
- return stream;
- }
- void check_argument_main(int num){
- if(num!=3){
- printf("Sorry,there is an issue.\n");
- printf("There is a mismatch with the arguments or\n "
- "you have inserted a wrong command\n");
- printf("The command format is the following:\n"
- "'command name', 'argument 1', 'argument 2'");
- exit(EXIT_FAILURE);
- }
- }
- void append_content(FILE *f1, FILE *f2){
- char c;
- while((c=getc(f1))!=EOF)
- putc(c,f2);
- fclose(f1);
- fclose(f2);
- }
- void copy_and_uppecase(FILE *f2,FILE *f3){
- char ch;
- while((ch=fgetc(f2))!=EOF){
- ch = toupper(ch);
- fputc(ch,f3);
- }
- fclose(f2);
- fclose(f3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement