-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountFileContent.c
More file actions
37 lines (33 loc) · 947 Bytes
/
Copy pathcountFileContent.c
File metadata and controls
37 lines (33 loc) · 947 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
//counting character , line and words in a file
#include <stdio.h>
#include <stdlib.h>
void main()
{
char c,filename[]="filecontainervariables";
int word=0,line=0,character=0;
system("cls");
FILE *fileAddress;
printf("===counting number of characters ,words and lines in a file===\n ");
printf("\nEnter file name with extension ");
scanf("%s",filename);
fileAddress = fopen(filename,"r");
if(fileAddress == NULL)
printf("file not fount\n");
else
{
while((c = fgetc(fileAddress)) != EOF)
{
if(c == ' ')
word++;
if(c== '\n')
line++;
character++;
}
printf("\n'%s' file contains \n",filename);
printf("\nNumber of words %d",word);
printf("\nNumber of line %d",line+1);
printf("\nNumber of Character %d\n",character);
}
fclose(fileAddress);
system("pause");
}