English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

find out the number of lines starting with alphabet A

2006-11-19 21:35:01 · 4 answers · asked by asawaridhande 1 in Computers & Internet Programming & Design

4 answers

Use the character '\n' while you write things into the file.

The logic of what you meant there would be:
1. Open the file.
2. Read line or use the getline(). It reads lines individually and stores it into a string. IT automatically moves the file pointer to the next position. (You can know that using fseek() function)
3. Once you got the string, search for the alphabet 'A'
4. If you have the alphabet then increase you line counter by 1.

2006-11-21 03:00:11 · answer #1 · answered by deostroll 3 · 0 0

I assume that u want to handle files in C++ using the fstream class library...
Entering multiple lines in a file is easy... just write endl into the file... I'll show you how:

fstream myFile( "newline.fil" , ios::in | ios::out );
myFile<<"This is the first line";
myFile< myFile<<"Now comes the second line";

Easy!!

and as to your second problem...
all you have to do is take a temporary string as a buffer and extract the contents of the file line by line using the getline function.

I'll show you how...

ifstream myInputFile( "input.fil" );
char buf[128]; // the temporary buffer
int counter=0; // this will count the number of lines.

while( myInputFile.good() )
{
myInputFile.getline( buf );
if( buf[0]=='A' ) counter++;
}

Easy!!

Yours
The Bazeegar

2006-11-19 22:12:43 · answer #2 · answered by Harry Bazeegar 2 · 2 0

I accept as true with answer no. 2. No in the present day forward technique. steps.. a million.U could first study each and all of the relax documents from component of insertion into yet another temp report. 2.clean the documents u copied.(uncertain if u choose for this step) 3.Write ur riquired documents. 4.Now reproduction the contents of the temp report back to unique report below append mode. step 2 won't be mandatory reason the "end of report" mark would be switched placed right here, verify this out.

2016-11-25 20:56:14 · answer #3 · answered by ? 4 · 0 0

WHAT DO YOU MEAN BY THIS!!!

2006-11-19 22:00:29 · answer #4 · answered by Kerov Rickardo 2 · 0 0

fedest.com, questions and answers