Advertisement
AlexandruFilipescu

C++ Count number of words excluding commas, dots and white space.

Aug 6th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main() {
  11.     int nr_cuvinte;
  12.     char virgula[1] = { ',' };
  13.     char punct = '.';
  14.     char cuvant[10];
  15.     nr_cuvinte = 0;
  16.  
  17.     ifstream f("cuvant.txt");
  18.     while (f>>cuvant) {
  19.         int rezultat = strcmp(cuvant,",");
  20.         int rezultat2 = strcmp(cuvant, ".");
  21.         if (rezultat != 0 && rezultat2 !=0 ) {
  22.             nr_cuvinte++;
  23.         }
  24.  
  25.        
  26.     }
  27.    
  28.     cout << "Am descoperit " << nr_cuvinte << " cuvinte";
  29.  
  30.     system("pause");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement