Hi,
I am trying to write a program in Dev CPP to hold the value of command in argv[0]
e.g. : echo welcome devcpp
argc = 3
argv[0] = echo
argv[1] = welcome
argv[2] = devcpp
However, when I am trying to execute this program(below is the code snippet), the argc[0] is having the value of abc.exe
trying to execute it as
Folder>abc.exe echo welcome devcpp
argv[0] = abc.exe
argv[1] = echo
..
How do I execute the program in order to get the intended result? Any idea?
# File - abc.cpp
main(int argc, char *argv[])
{
if (argc <= 0)
printf("ERROR");
else
printf("\nnumber of arguments = %d\n",argc);
====
more codes
====
}
Okay, I got the solution. I need to rename the .exe file as per the first argument argv[0].
argv[0] will always be the executable file. You need to start with argv[1]