Batch File Utilities

I am working on a pack of Batch File utilities; however, one of them I have been having trouble with. I can't seem to get an input from the command line (Or batch file...) to my C++ program to make it change text color, I can't see where I went wrong in my code, it is very very simple... anyways the problem is that when I get an input and put it through the SetConsoleTextAttribute() function, it has the same output, the text is gray with a purple background, regardless of the input. Any help is much appreciated...

Code:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>
#include <Windows.h>

int main(int argc, char* argv[] = (char**)"4")
{
	int c = (int)argv;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
	std::cout << "Hi!" << std::endl;
	system("pause");
}


The output (image):
http://i60.tinypic.com/fejw3o.png


Edit::
Another thing that could cause problems is the (int)argv, is there a way to check for sure that c is an int before using it??? Thank you!
Last edited on
argv is always an array of strings. You need to convert it to a number:
1
2
3
4
5
6
7
8
9
int main(int argc, char* argv[] = (char**)"4")
{
        if (argc <2) return 1; // no argument
	int c = atoi(argv[1]);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
	std::cout << "Hi!" << std::endl;
	system("pause");
        return 0;
}
i usually just put argv in something like this: vector<string> args(argv, argv+argc) then just run it through a switch
Thank you! Works wonders
Topic archived. No new replies allowed.