Skip to content

Instantly share code, notes, and snippets.

@zvakanaka
Created April 8, 2016 03:33
Show Gist options
  • Save zvakanaka/7d489259783990f4bb38145ba2bc5f4d to your computer and use it in GitHub Desktop.
Save zvakanaka/7d489259783990f4bb38145ba2bc5f4d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(int argc, char **argv)
{
int i = 0;
int color[] = {31, 33, 32, 34, 35};
char fileName[256];
char letter;
if (argc < 2)
{
cout << "File Name? ";
cin.getline(fileName, 256);
}
else
strcpy(fileName, argv[1]);
ifstream fin;
fin.open(fileName);
if (fin.fail())
{
cout << "ERROR: " << fileName << " does not exist\n";
return 1;
}
i = 0;
for (int c = 0; ! fin.eof(); i++)
{
if (c > 4)
c = 0;
fin.get(letter);
cout << "\E[1;" << color[c] << "m";
cout << letter;
if (letter != ' ')
c++;
}
cout << "\E[0m";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment