-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_practice_solutions.c
More file actions
43 lines (36 loc) · 896 Bytes
/
file_practice_solutions.c
File metadata and controls
43 lines (36 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
void copy_cap(FILE*, FILE*, FILE*);
int main(int argc, char *argv[])
{
if (argc != 4)
{
printf("Usage: ./copy infile copy_outfile capitalized_outfile\n");
return 1;
}
FILE *infile = fopen(argv[1], "r");
FILE *copy_outfile = fopen(argv[2], "w");
FILE *capitalized_outfile = fopen(argv[3], "w");
// Copy file:
copy_cap(infile, copy_outfile, capitalized_outfile);
fclose(infile);
fclose(copy_outfile);
fclose(capitalized_outfile);
}
void copy_cap(FILE *infile, FILE *copy_outfile, FILE *capitalized_outfile)
{
while (true)
{
char c = fgetc(infile);
if (c == EOF)
{
return;
}
fputc(c, copy_outfile);
fputc(toupper(c), capitalized_outfile);
}
}