| | |
To fetch data through command line arguments
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi All.
I m a C++ programmer and I m trying to understand a piece of code.
It fetches the values through command line arguments and makes a decision on the basis of these values. This code is working well but I dont know how?
kindly tell me how does it work...?
I m a C++ programmer and I m trying to understand a piece of code.
It fetches the values through command line arguments and makes a decision on the basis of these values. This code is working well but I dont know how?
C++ Syntax (Toggle Plain Text)
for (int i = 0; i < argc; i++) if (strnicmp(argv[i],"/id",3) == 0) { strncpy(ID,argv[i] + 3,40); //ID is defined as a char array of size 40 }
kindly tell me how does it work...?
argc is the number of strings in the argv array. argv[0] is always the name of the executable program and will never ever contain a command-line argument.
>>argv[i] + 3
all that does is bypass the first 3 characters of the ith string.
The algorithm you posted doesn't work at all if you put a space between "/id" and whatever is supposed to follow. For example, if you typed this:
In the above the program will get two command-line arguments, not one. argv[1] will be "/cd" and argv[2] will be "something". And that will break the algorithm you posted.
>>argv[i] + 3
all that does is bypass the first 3 characters of the ith string.
The algorithm you posted doesn't work at all if you put a space between "/id" and whatever is supposed to follow. For example, if you typed this:
C++ Syntax (Toggle Plain Text)
c:\myprogram /id something <Enter key>
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Thanks for the help.
Would You please tell me that why it will not work for space, if i give arguments as
Would You please tell me that why it will not work for space, if i give arguments as
C++ Syntax (Toggle Plain Text)
c:\myprogram /idTheAdminId /pwTheAdminPw
It will work for the arguments you posted, but not for this
C++ Syntax (Toggle Plain Text)
c:\myprogram /id TheAdminId /pw TheAdminPw
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Command Line Arguments (C#)
- command line arguments help (C)
- HELP!!!need help with command line arguments and creating a package in java. HELP!!!! (Java)
- command line arguments (C++)
- Command-line Arguments. (C++)
Other Threads in the C++ Forum
- Previous Thread: Unresolved External Symbol Error
- Next Thread: How do I plot a graph using C++?
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






