hey again,
code below works but it tends to give some info which shouldn't be there:
(for example a - 0 where 'a' is a letter and 0 is the times the letter was repeated)
#include <iostream>
#include <stack>
#include <fstream>
using namespace std;
int main()
{
fstream fin1("E:\\iras.txt", ios::in | ios::binary);
if (!fin1) { cout<< "error"; return 0; }
//========================================================
string text;
while (!fin1.eof())
fin1 >> text;
const char *textCopy=text.c_str();
//========================================================
stack <char> symbol;
int index=0;
//========================================================
cout<< "letter/digit count: \n";
for (char j='0'; j< 'z'; j++)
{
symbol.push(j);
for (int i=0; i<text.size(); i++)
{
if (textCopy[i] == symbol.top())
{ index++; }
}
if ((index > 0) && (symbol.top() >= '0' && symbol.top() <= '9') ||
(symbol.top() >= 'A' && symbol.top() <= 'Z') || (symbol.top() >= 'a' && symbol.top() <= 'z'))
//these lines check for the symbols i need
{
cout<< j << " - " << index <<endl;
index=0;
symbol.pop();
}
else index=0;
}
fin1.close();
return 0;
}
i generated chars using the following code
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
int main()
{
fstream fout1("E:\\iras.txt", ios::out | ios::binary);
if (!fout1) { cout<< "error"; return 0; }
char symbol;
stack <char> storage;
srand(time(NULL));
for (int i=1; i<300; i++)
{
symbol=48 + rand() % 74;
if ((symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z') ||
(symbol >= '0' && symbol <= '9'))
storage.push(symbol);
fout1 << storage.top();
}
fout1.close();
return 0;
}
and also, any quick tips on what should have better been left out / done differently in this task?