2023-07-01 11:58:00 -04:00
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2026-04-30 12:34:36 -04:00
|
|
|
std::ifstream input("filename.txt", std::ios_base::binary);
|
|
|
|
|
if (!input)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "error: can't open file\n";
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2023-07-01 11:58:00 -04:00
|
|
|
|
2026-04-30 12:34:36 -04:00
|
|
|
size_t count[256];
|
|
|
|
|
std::fill_n(count, 256, 0);
|
2023-07-01 11:58:00 -04:00
|
|
|
|
2026-04-30 12:34:36 -04:00
|
|
|
for (char c; input.get(c); ++count[uint8_t(c)]) // process input file
|
|
|
|
|
; // empty loop body
|
2023-07-01 11:58:00 -04:00
|
|
|
|
2026-04-30 12:34:36 -04:00
|
|
|
for (size_t i = 0; i < 256; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (count[i] && isgraph(i)) // non-zero counts of printable characters
|
|
|
|
|
{
|
|
|
|
|
std::cout << char(i) << " = " << count[i] << '\n';
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-01 11:58:00 -04:00
|
|
|
}
|