-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileHandling17.c
73 lines (66 loc) · 1.55 KB
/
FileHandling17.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* C Program to Convert the Content of File to UpperCase
*/
#include <stdio.h>
int to_upper_file(FILE *);
int main(int argc,char *argv[])
{
FILE *fp;
int status;
if (argc == 1)
{
printf("Insufficient Arguments:");
printf("No File name is provided at command line");
return;
}
if (argc > 1)
{
fp = fopen(argv[1],"r+");
status = to_upper_file(fp);
/*
*If the status returned is 0 then the coversion of file content was completed successfully
*/
if (status == 0)
{
printf("\n The content of \"%s\" file was successfully converted to upper case\n",argv[1]);
return;
}
/*
* If the status returnes is -1 then the conversion of file content was not done
*/
if (status == -1)
{
printf("\n Failed to convert");
return;
}
}
}
/*
* convert the file content to uppercase
*/
int to_upper_file(FILE *fp)
{
char ch;
if (fp == NULL)
{
perror("Unable to open file");
return -1;
}
else
{
/*
* Read the file content and convert to uppercase
*/
while (ch != EOF)
{
ch = fgetc(fp);
if ((ch >= 'a') && (ch <= 'z'))
{
ch = ch - 32;
fseek(fp,-1,SEEK_CUR);
fputc(ch,fp);
}
}
return 0;
}
}