Code:
#include <stdio.h>
int main (void)
{
int Counter;
for(Counter = 0; Counter < 5; Counter++)
{
printf("Loop process %d\n", Counter);
RunBatch(Counter);
printf("\n");
}
return 0;
}
int RunBatch(int Counter)
{
int LoopCount = 0;
while(LoopCount < Counter)
{
LoopCount = LoopCount+1;
printf("This loop is on iteration %d.\n", LoopCount);
}
return 0;
}
How would I change the second parameter in the above code located in the first for loop so that I may input what is currently 5, as any number from the command-line instead, hence filtering through the rest of the program and furthermore allowing control by means of one command line parameter.
Code:
int main ( int argc, char * argv[] )
{
if (argc == 2)
{
if(argv[1][0] == '?')
{
printf("Help stuff would go here.\n");
}
else
{
printf("%s \n", argv[1]); /* This is the line I'm trying to replace */
}
}
else if ( argc >= 3 )
{
printf("Invalid input:\n");
printf("Only one command-line parameter allowed.\n");
}
else
{
DefaultMessage();
}
return 0;
}
void DefaultMessage ( void )
{
printf("CmdLine.exe:\n");
printf("The purpose of this program is to demonstrate command line arguments.\n");
printf("This program will print whatever you type on the screen.\n\n");
printf("Example:\n");
printf("C:\\>CmdLine.exe Hmmm\n");
printf("Hmmm\n");
}
I tried culturing the first program into this one by means of a function call, and passing the 2nd command-line parameter straight to my function, but it doesn't register. My loop just spins out of control. I think that's because this command-line code I'm using captures text from the line, not raw integers - which is what I need for my idea, yes?
Any ideas?