Hi friends,
I have a small query, hope u will help me with it.
I want to write a small program which would take an integer as an argument, then I want to save that argument in a variable of type int. Could you please help me with it. Here is my program
#include <stdio.h>
int main(int argc, char *argv[])
{
int x;
x = argv[1];
printf("%d\n",argv[1]);
return 0;
}
This program cannot be compiled, it says that there is some problem with type conversion or something. Could you please help me with this thing!
C is not a scripting language, you can't cavalierly assign a string into an integer and expect to get anything sensible. If you try and force it with typecasting, it will take you completely literally and put the wrong type in, giving you results you didn't expect at best and crashing your program at worst.