MENU
Question -

Write a function CountDig() in C++ which reads the content of a text file story.txt and displays the number of digits in it
For example if the file contains:
Amrapali was a queen of Gareware Kingdom in the year 1911. She had 2 daughters.
Her palace had 200 rooms.
Then the output on the screen should be :
Number of digits in Story: 8



Answer -

void CountDig ()
 {
 ifstream fin ("STORY.TXT");
 char ch;
 int count=0;
 while(!fin.eof ())
 {fin>>ch;
 if(isdigit(ch))
 count++;
 }
 cout<<"Number of digit in Story: "<
 fin:close();
 }

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×