Jumat, 04 April 2014

Count number of characters blanks tabs lines numerals of a file

,
/* 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==
)

  nol++;
  if(ch== )
  not++;
  if(ch>=48 && ch<=57)
  non++;
 }
 fclose(fp);
 printf("
Number of characters = %d",noc);

 printf("
Number of blanks = %d",nos);

 printf("
Number of tabs = %d",not);

 printf("
Number of lines = %d",nol);

 printf("
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:


0 komentar to “Count number of characters blanks tabs lines numerals of a file”

Posting Komentar

 

Android Info and App Copyright © 2016 -- Powered by Blogger