thnks for your help last time but my professor just increased the problem by saying the time value should be passed as command line arguments
can anybdy tell the code to parse time as command line arguments
p s: i dont have any idea about that, so havnt written any code
for example in the command prompt in windows
if i write UPDATE TIME 09:13:12
then this parameter should get passed to my code where i have to store it in a file.
i have no idea how some parameters are passed from command line to a code
You can use those mystical argc and argv arguments for main:
1 2 3 4 5 6 7 8 9 10 11
int main( //Put on separate lines, so the comments are neater
int argc, //The number of arguments passed; always at least 1
char* argv //Also char** argv; contains the actual arguments as an array of C-strings
std::cout << "Time to print some arguments:\n";
for(int I(0); I < argc; ++I)
std::cout << '\t' << *argv[I] << '\n';
You will notice that the first argument will always be the name of the program.
You don't need to check the value of argv as that will be the name of the program you have compiled. If you are passing the time as @Daleth suggested then you will have two arguments so you should check that argc == 2 and then attempt to extract the time from the second argv i.e. argv (it's zero based). Why do you need to parse the time, can't you just use it or did your professor tell you that you must validate the time as being a valid time? Try to write separate functions that just do exactly what their name implies. So if you must validate the time argv then:
Would be a suitable function template, so you then need to write the code and pass the argv through to it. If it's valid then carry on with your program, otherwise if its wrong inform the user and exit(1) from your program.
You also don't have any comments, so I moved things around so I could read it easier. I really only changed 2 things where you see the commented out lines. My program was not named set_time so I removed those lines, the main reason it did not work is you had a extra