Write a function in C++ to count and display the number of lines not starting with alphabet 'A' present in a text file "STORY.TXT".

 Write a function in C++ to count and display the number of lines not starting with
alphabet 'A' present in a text file "STORY.TXT".

Example:
If the file "STORY.TXT" contains the following lines,
The roses are red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
The function should display the output as 3.


#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ifstream fin;
    fin.open("Story.txt");
   
    char str[100];
    int count=0;
    int count1=0;
   
    while(!fin.eof())
    {
        fin.getline(str,100);
        if(str[0]!='A')
        {
            count++;
        }
        else if(str[0]=='A'&&str[1]==' ')
        {
            count1++;
        }
    }
   
    cout<<"The number of lines not starting with 'A' are:"<<count<<"\n";
    cout<<"The number of lines starting with 'A' are:"<<count1<<"\n";
   
    fin.close();
    return 0;
}

Comments

  1. bro your code is not working

    ReplyDelete
  2. Casino Games - JTM Hub
    In the latest 전라북도 출장마사지 news about casino games, check out the latest 충주 출장샵 information 밀양 출장샵 about 군산 출장마사지 your Casino Games, 문경 출장마사지 your top-rated options and top-rated bonuses. Get more!

    ReplyDelete

Post a Comment

Popular posts from this blog

Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array.

C++ program that creates an output file, writes information to it, closes the file and open it again as an input file and read the information from the file.

Write C++ program using STL for Sorting and searching