hope you are all keeping well. I am doing a little project or muck about with C++, i'm relatively new to C++ so I kinda dont know really what is happening however. I thought it would be pretty cool to try and design some sort of program that will analyse some text and then count how many of times each character in the text file occurs and hopefully it will print out to the console. Once I rann it, it runs (no errors) but when I get a message about the number of characters in file is 0 when its clearly not, then it gives me something like "A has occurred 0" below is an example
e.g
"A" occurs 5 times "B" occurs 8 times "C" occurs 4 times etc...
I have attached C++ code and the text file below. I would appreciate it if you could look at it and tell me what is wrong with it, thank you
#include <iostream>
#include <fstream>
#include <vector>
int main(int argc, char* argv[])
{
using namespace std;
ifstream encryptedtxt ("Encrypted_text");
char readCharacter;
vector <char> characterVector;
while(encryptedtxt >> readCharacter)
{
characterVector.push_back(readCharacter);
}
cout << "The number of characters in this file is" << characterVector.size() << endl;
char currentCharacter;
while(true)
{
int counter = 0;
cout << "Please Enter the character you want to check occurence of:";
cin >> currentCharacter;
for(int i = 0; characterVector.size(); i++)
{
if(currentCharacter==characterVector[i] )
{
counter++;
}
}
cout << "This Character:" << currentCharacter << "has occured:" << counter << "many times" << endl;
}
return 1;
}
Encrypted_text file
Ftq O Bdasdmyyuzs Xmzsgmsq (eayqfuyqe dqrqddqp fa me W&D, mrfqd ufe mgftade' uzufumxe) ue m oaybgfqd bdasdmyyuzs naaw
iduffqz nk Ndumz Wqdzustmz mzp Pqzzue Dufotuq, ftq xmffqd ar itay adusuzmxxk pqeuszqp mzp uybxqyqzfqp ftq xmzsgmsq,
me iqxx me oa-pqeuszqp ftq Gzuj abqdmfuzs ekefqy iuft ituot pqhqxabyqzf ar ftq xmzsgmsq ime oxaeqxk uzfqdfiuzqp.
Ftq naaw ime oqzfdmx fa ftq pqhqxabyqzf mzp babgxmdulmfuaz ar ftq O bdasdmyyuzs xmzsgmsq mzp ue efuxx iupqxk dqmp mzp geqp
fapmk. Nqomgeq ftq naaw ime oa-mgftadqp nk ftq adusuzmx xmzsgmsq pqeuszqd, mzp nqomgeq ftq rudef qpufuaz ar ftq naaw eqdhqp
rad ymzk kqmde me ftq pq rmofa efmzpmdp rad ftq xmzsgmsq, ftq naaw ime dqsmdpqp nk ymzk fa nq ftq mgftadufmfuhq dqrqdqzoq az O.
Tuefadk
Ftq rudef qpufuaz ar ftq naaw, bgnxuetqp uz 1978, ime ftq rudef iupqxk mhmuxmnxq naaw az ftq O bdasdmyyuzs xmzsgmsq. O ime odqmfqp nk Pqzzue Dufotuq. Ndumz Wqdzustmz idafq ftq rudef O fgfadumx.[3] Ftq mgftade omyq fasqftqd fa idufq ftq naaw uz oazvgzofuaz iuft ftq xmzsgmsq'e qmdxk pqhqxabyqzf mf MF&F Nqxx Xmne. Ftq hqdeuaz ar O pqeodunqp uz ftue naaw ue eayqfuyqe dqrqddqp fa me W&D O (mrfqd ftq naaw'e mgftade), arfqz fa puefuzsguet ftue qmdxk hqdeuaz rday ftq xmfqd hqdeuaz ar O efmzpmdpulqp me MZEU O.
Uz 1988, ftq eqoazp qpufuaz ar ftq naaw ime bgnxuetqp, gbpmfqp fa oahqd ftq otmzsqe fa ftq O bdasdmyyuzs xmzsgmsq dqegxfuzs rday ftq ftqz-zqi MZEU O efmzpmdp, bmdfuogxmdxk iuft ftq uzoxgeuaz ar dqrqdqzoq ymfqdumx az efmzpmdp xundmduqe. Ftq eqoazp qpufuaz (mzp me ar 2016, ftq yaef dqoqzf qpufuaz) ar ftq naaw tme euzoq nqqz fdmzexmfqp uzfa ahqd 20 xmzsgmsqe. Uz 2012 mz qNaaw hqdeuaz ar ftq eqoazp qpufuaz ime bgnxuetqp uz qBgn, Yanu, mzp BPR radymfe.
MZEU O, rudef efmzpmdpulqp uz 1988, tme euzoq gzpqdsazq eqhqdmx dqhueuaze, ftq yaef dqoqzf ar ituot ue UEA/UQO 9899:2011 (mxea wzaiz me "O11"), mpabfqp me mz MZEU efmzpmdp uz Aofanqd 2011. Taiqhqd, za zqi qpufuaz ar Ftq O Bdasdmyyuzs Xmzsgmsq tme nqqz ueegqp fa oahqd ftq yadq dqoqzf efmzpmdpe.
Dqoqbfuaz
NKFQ efmfqp uz Mgsgef 1983, "[Ftq O Bdasdmyyuzs Xmzsgmsq] ue ftq pqruzufuhq iadw az ftq O xmzsgmsq. Paz'f dqmp mzk rgdftqd gzfux kag tmhq ftue naaw!"[1] Vqddk Bagdzqxxq idafq uz ftq ymsmluzq ftmf kqmd ftmf ftq naaw "ue efuxx ftq efmzpmdp ... m nuf fqdeq". Tq oazfuzgqp, "Kag omz xqmdz ftq O xmzsgmsq iuftagf sqffuzs Wqdzustmz mzp Dufotuq, ngf ftmf'e pauzs uf ftq tmdp imk. Kag'dq mxea iadwuzs faa tmdp ur kag ymwq uf ftq azxk naaw az O ftmf kag ngk."[5]
Uzrxgqzoq
Ftq O Bdasdmyyuzs Xmzsgmsq tme arfqz nqqz oufqp me m yapqx rad fqotzuomx idufuzs, pgq fa ftq naaw'e oxqmd bdqeqzfmfuaz mzp oazoueq fdqmfyqzf. Uz vgef 228 bmsqe (272 bmsqe uz ftq eqoazp qpufuaz), ftq naaw oahqde O oaybdqtqzeuhqxk. Qjmybxqe sqzqdmxxk oazeuef ar oaybxqfq bdasdmye ar ftq fkbq azq ue xuwqxk fa qzoagzfqd uz pmuxk gemsq ar ftq xmzsgmsq, iuft mz qybtmeue az ekefqy bdasdmyyuzs. Ftq fqotzuomx pqfmuxe ar O mdq nmxmzoqp nk ftq mgftade' aneqdhmfuaze az saap bdasdmyyuzs bdmofuoq, ituot mdq uyyqpumfqxk uxxgefdmfqp iuft oazodqfq, dqmxuefuo qjmybxqe.
Iq tmhq fduqp fa dqfmuz ftq ndqhufk ar ftq rudef qpufuaz. O ue zaf m nus xmzsgmsq, mzp uf ue zaf iqxx eqdhqp nk m nus naaw. Iq tmhq uybdahqp ftq qjbaeufuaz ar odufuomx rqmfgdqe, egot me bauzfqde, ftmf mdq oqzfdmx fa O bdasdmyyuzs. Iq tmhq dqruzqp ftq adusuzmx qjmybxqe, mzp tmhq mppqp zqi qjmybxqe uz eqhqdmx otmbfqde. Rad uzefmzoq, ftq fdqmfyqzf ar oaybxuomfqp pqoxmdmfuaze ue mgsyqzfqp nk bdasdmye ftmf oazhqdf pqoxmdmfuaze uzfa iadpe mzp huoq hqdem. Me nqradq, mxx qjmybxqe tmhq nqqz fqefqp pudqofxk rday ftq fqjf, ituot ue uz ymotuzq-dqmpmnxq rady.
Bqdtmbe ftq yaef rmyage qjmybxq bdasdmy rday ftq naaw ue ufe "tqxxa, iadxp" bdasdmy, ituot vgef bduzfe agf ftq fqjf "tqxxa, iadxp", me mz uxxgefdmfuaz ar m yuzuymx iadwuzs O bdasdmy. Zgyqdage fqjfe euzoq ftqz tmhq raxxaiqp ftmf oazhqzfuaz rad uzfdapgouzs m bdasdmyyuzs xmzsgmsq.
Nqradq ftq mphqzf ar MZEU O, ftq rudef qpufuaz ar ftq fqjf eqdhqp me ftq pq rmofa efmzpmdp ar ftq xmzsgmsq rad idufqde ar O oaybuxqde. Iuft ftq efmzpmdpulmfuaz ar MZEU O, ftq mgftade yadq oazeouagexk sqmdqp ftq eqoazp qpufuaz faimdp bdasdmyyqde dmftqd ftmz oaybuxqd idufqde; uz ftq mgftade' aiz iadpe:
Mbbqzpuj M, ftq dqrqdqzoq ymzgmx, ue zaf ftq efmzpmdp, ngf agd mffqybf fa oazhqk ftq qeeqzfumxe ar ftq efmzpmdp uz m eymxxqd ebmoq. Uf ue yqmzf rad qmek oaybdqtqzeuaz nk bdasdmyyqde, ngf zaf me m pqruzufuaz rad oaybuxqd idufqde—ftmf daxq bdabqdxk nqxazse fa ftq efmzpmdp ufeqxr. Mbbqzpuj N ue m egyymdk ar ftq rmouxufuqe ar ftq efmzpmdp xundmdk. Uf faa ue yqmzf rad dqrqdqzoq nk bdasdmyyqde, zaf uybxqyqzfqde. Mbbqzpuj O ue m oazoueq egyymdk ar ftq otmzsqe rday ftq adusuzmx hqdeuaz.
Ftq uzrxgqzoq ar Ftq O Bdasdmyyuzs Xmzsgmsq az bdasdmyyqde, m sqzqdmfuaz ar itay rudef iadwqp iuft O uz gzuhqdeufuqe mzp uzpgefdk, tme xqp ymzk fa mooqbf ftq mgftade' bdasdmyyuzs efkxq mzp oazhqzfuaze me dqoayyqzpqp bdmofuoq, ur zaf zadymfuhq bdmofuoq. Rad qjmybxq, ftq oapuzs mzp radymffuzs efkxq ar ftq bdasdmye bdqeqzfqp uz naft qpufuaze ar ftq naaw ue arfqz dqrqddqp fa me "W&D efkxq" ad ftq "Azq Fdgq Ndmoq Efkxq" mzp, euszuruomzfxk, nqomyq ftq oapuzs efkxq geqp nk oazhqzfuaz uz ftq eagdoq oapq rad ftq Gzuj mzp Xuzgj wqdzqxe.
Aucun commentaire:
Enregistrer un commentaire