-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileHandling18.c
53 lines (49 loc) · 991 Bytes
/
FileHandling18.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
/*
* C Program to replace first letter of every word with caps
*/
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[])
{
FILE *fp1;
int return_val;
if ((fp1 = fopen(argv[1],"r+")) = = NULL)
{
printf("file cant be opened");
exit(0);
}
return_val = init_cap_file(fp1);
if (return_val == 1)
{
printf("\nsuccess");
}
else
{
printf("\n failure");
}
}
int init_cap_file(FILE *fp1)
{
char ch;
ch = fgetc(fp1);
if (ch >= 97 && ch <= 122)
{
fseek(fp1, -1L, 1);
fputc(ch - 32, fp1);
}
while (ch != EOF)
{
if (ch = = ' '|| ch == '\n')
{
ch = fgetc(fp1);
if (ch >= 97 && ch <= 122)
{
fseek(fp1, -1L, 1);
fputc(ch - 32, fp1);
}
}
else
ch = fgetc(fp1);
}
return 1;
}