Why it keeps giving me a zero answer ?!!! even though there IS a text file to search in it !!
//a C++ project that reads a text from an input file and writes the same text into an output and find how much symbols are there
#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
using namespace std;
ifstream infile;
ofstream outfile;
void tokenize ();
void statistic ();
int main()//the main function is gonna to call func tokenize first then the func statistis
{
tokenize ();
statistic ();
return 0;
}
void tokenize()//the tokenize function is gonna ask the user to type their txet in input file then it's re-write it on output file
{
cout<<"Please write your txet in your file that have been called input"<<endl;
infile.open("input.txt");
outfile.open("output.txt");
string x;
while(!infile.eof())
{
infile>>x; //write something in the text
outfile<<x<<endl; //the writting in the input file is ganna to be re-wrote in output file each word in new line
}
}
void statistic()//the tokenize function is gonna ask the user to type their txet in input file then it's re-write it on output file
{
string word;
infile.open("input.txt");
int dot=0, comma=0, questionmark=0, exclamationmark=0, doublequotation=0;
while (!infile.eof())
{
infile>>word;
for (int i=0; !infile.eof(); i++)
{
if (word == ".")
dot++;
else
if (word == ",")
comma++;
else
if (word == "?")
questionmark++;
else
if (word == "!")
exclamationmark++;
else
if (word == "\"")
doublequotation++;
}
cout<<"Number of dots in the txet: "<<dot<<endl;
cout<<"Number of commas in the txet: "<<comma<<endl;
cout<<"Number of question marks in the txet: "<<questionmark<<endl;
cout<<"Number of exclamation marks in the txet: "<<exclamationmark<<endl;
cout<<"Number of double quotation marks in the txet: "<<doublequotation<<endl;
}