I was trying to access an integer input via command line [on windows].
Eg:
If I want to reverse an integer where the integer is input via command line, then how do I implement the code for the same?
I tried to use typecasting but that doesn't seem to work :(
here is a bit of the code I could come up with
void main(int argc, char **argv)
{
int i = 0, j =0, k = 0;
[B] k = (int) argv[1];[/B] // this is causing the problem.
printf("%d", k); // used this statement to check the value returned via typecasting. Always a junk value came up
while( k !=0)
{
i = k % 10;
j = (j * 10) + i;
k = k/10;
printf("%d", j);
}
}
so what is the right way of using integers via command line?


Sign In
Create Account

Back to top









