-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproblem5.c
58 lines (56 loc) · 1.22 KB
/
problem5.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int is_vowel(int ch)
{
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return 1;
}
return 0;
}
int main(void)
{
char wrong[50], right[50];
int i, j;
FILE *fptr1, *fptr2;
if ((fptr1 = fopen("wrong.txt", "r")) == NULL)
{
printf("Error in openning file\n");
exit(1);
}
if ((fptr2 = fopen("right.txt", "w")) == NULL)
{
printf("Error in openning file\n");
exit(1);
}
while ((fgets(wrong, 100, fptr1)) != NULL)
{
i = j = 0;
while (wrong[i] != '\0')
{
if (islower(wrong[i]) && (i == 0 || wrong[i - 1] == '.'))
right[j++] = toupper(wrong[i++]);
else if (wrong[i] == ' ' && wrong[i - 1] == 'a' && is_vowel(wrong[i + 1]))
{
right[j++] = 'n';
right[j++] = wrong[i++];
}
else
right[j++] = wrong[i++];
}
right[j] = '\0';
fputs(right, fptr2);
}
}