Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. // plik2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <fstream>
  8. using namespace std;
  9.  
  10. int sprawdz(string);
  11.  
  12. int _tmain(int argc, _TCHAR* argv[])
  13. {
  14.     string nazwa;
  15.     cout << "Podaj nazwe pliku: ";
  16.     cin >> nazwa;
  17.     cout << endl;
  18.     try{
  19.         cout << sprawdz(nazwa);
  20.     }catch(const char *wyjatek){
  21.         cout << wyjatek;
  22.     }
  23.     system("pause");
  24.     return 0;
  25. }
  26.  
  27. int sprawdz(string nazwa){
  28.    
  29.         fstream plik;
  30.         string tekst;
  31.         plik.open(nazwa);
  32.         if(!plik.is_open()){
  33.             throw "blad!";
  34.         }
  35.             getline(plik, tekst);
  36.             int licznik = 0, dlugosc = tekst.length();
  37.             if((tekst[0] == 'a' || tekst[0] == 'A') && tekst[1] != ' '){
  38.                 licznik++;
  39.             }
  40.             for(int i=1;i<(dlugosc-1);i++){
  41.                 if((tekst[i] == 'a' || tekst[i] == 'A') && tekst[i-1] == ' ' && tekst[i+1] != ' '){
  42.                     licznik++;
  43.                 }
  44.             }
  45.             //cout << tekst;   
  46.        
  47.     return licznik;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement