Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // plik2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- int sprawdz(string);
- int _tmain(int argc, _TCHAR* argv[])
- {
- string nazwa;
- cout << "Podaj nazwe pliku: ";
- cin >> nazwa;
- cout << endl;
- try{
- cout << sprawdz(nazwa);
- }catch(const char *wyjatek){
- cout << wyjatek;
- }
- system("pause");
- return 0;
- }
- int sprawdz(string nazwa){
- fstream plik;
- string tekst;
- plik.open(nazwa);
- if(!plik.is_open()){
- throw "blad!";
- }
- getline(plik, tekst);
- int licznik = 0, dlugosc = tekst.length();
- if((tekst[0] == 'a' || tekst[0] == 'A') && tekst[1] != ' '){
- licznik++;
- }
- for(int i=1;i<(dlugosc-1);i++){
- if((tekst[i] == 'a' || tekst[i] == 'A') && tekst[i-1] == ' ' && tekst[i+1] != ' '){
- licznik++;
- }
- }
- //cout << tekst;
- return licznik;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement