-
Notifications
You must be signed in to change notification settings - Fork 1
/
program2.c
43 lines (40 loc) · 918 Bytes
/
program2.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
// read a file and count no of characters, no of words and no of lines in the file.
//File Handling
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int check_v(char a){
int chk=0;
a = tolower(a);
if(a=='a' ||a=='e' ||a=='i'||a=='o'||a=='u')
chk=1;
return chk;
}
void main(){
int v=0,w=0,i=0,z,l=0;
// OPENING A FILE AND READING FROM IT
FILE *rptr;
char ch;
rptr = fopen("text.txt","r");
if(rptr == NULL){
printf("\n\nFile not Found, Create a File in local directory and then run the program\n\n");
exit(1);
}
printf("Content of File is : ");
while((ch = getc(rptr)) != EOF){
z=check_v(ch);
if(z==1)
v++;
i++;
if(((ch<'a')||(ch>'z'))&&((ch<'A')||(ch>'Z')))
w++;
printf("%c",ch);
if(ch == '.')
l++;
}
if(l==0)
l++;
printf("\nNo of vowels is %d\nNo of characters is %d\nNo of white spaces are %d\nNo of lines are %d\n",v,i,w-1,l);
fclose(rptr);
}