So I'm confused on how exactly command line arguments work in C... so I have these command line arguments that I'm giving:
./myclient1 MyPCName 12 7894
So I want to read argv[2] (12)
as a String... but I'm confused exactly how values are stored in the command line. I looked at both this SO post,this this link but I'm still confused... what is the data type of argv[2]
? Is it an integer? Or are all command line arguments originally strings? So argv[2]
is actually:
argv:
[0]
[1]
[2] --> 1 | 2 | \0
I'm just really confused.... currently, I just converted to an integer using atoi()
and then converted back to a string using snprintf
, but it's not working correctly and I'm wondering if I need to do this at all.
I'm new to C so any help would be greatly appreciated, thanks!!
[edit]
this is what I had done before:
int main(int argc, char *argv[])
{
clientID = atoi(argv[2]);
snprintf(clibuff,300,"%d",clientID); //now clibuff has the value of
//clientID in a string.
}