/*
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
/* C++ program to determine number of characters, blanks, tabs, lines, numerals of a file. */
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
int nol=0,not=0,nos=0,noc=0,non=0;
clrscr();
fp=fopen("data.txt","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch==' ')
nos++;
if(ch=='\n')
nol++;
if(ch=='\t')
not++;
if(ch>=48 && ch<=57)
non++;
}
fclose(fp);
printf("\n Number of characters = %d",noc);
printf("\n Number of blanks = %d",nos);
printf("\n Number of tabs = %d",not);
printf("\n Number of lines = %d",nol);
printf("\n Number of Numerals = %d",non);
getch();
}
/*=========================24Nov.,2011=============================*/
Text File: data.txt
This program taken from http://world-of-c-programming.blogspot.com/
Check regualrly for new programs.
For testing-
some symbols: *&%$$^@!
some numbers: 23445673
some tab spaces: a b c
Output:
No comments:
Post a Comment
You are welcome, your comment helps me to make this blog more better.