word counter ,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
// dang.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string word;
char find[1000];
int count=0;
int i=1;
cout<<"search"
<<"enter word to count:";
cin>> word;
fstream file;
file.open("dang.txt");
if(file.fail()){cout<<"failed to initialize";}//-------------------------------fail
else while(!file.eof())
{
cin>>find[i];
if(find==word){count=count+1;}
i++;
}
cout << count;
return 0;
}
|
can u help me this code work for storing every word in a sentence in a variable, then if its == to the entered wored it will count as 1.
you shouldn't double post your problem :-/
sory sory i thougt i just post it in general c++, i delete the other one.
Topic archived. No new replies allowed.