read arguments from input

I have an assignment where i am to read arguments from the user. A special format is to be applied though. For example : -d 3 -D 3 -c 5 -u raw -g thisFile Thisnumber Thisoutput

In the example I am only supposed to read the numbers or string after -d -D -c and so on. I am not too too sure how to go about this. I was thinking of declaring an array of chars then read them individually but the length of the input can vary. Any suggestions?
closed account (18hRX9L8)
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <cstdio>

main()
{
	char thisfile[100],thisoutput[80];
	int thisnumber;
	
	scanf("-d 3 -D 3 -c 5 -u raw -g %s %d %s",thisfile,&thisnumber,thisoutput);
	std::cout<<"Thisfile="<<thisfile<<std::endl<<"Thisnumber="<<thisnumber<<std::endl<<"Thisoutput="<<thisoutput;
}


http://www.cplusplus.com/reference/cstdio/scanf/
closed account (3TXyhbRD)
You mentioned arguments. Did you mean command line arguments? If so your main should look like this:

int main(int argc, char* args[])

The following program will output all command line arguments.
1
2
3
4
5
6
7
#include <iostream>

int main(int argc, char* args[])
{
    for (int i = 0; i < argc; i++)
        std::cout << args[i] << std::endl;
}
Yes I did mean command line arguments. Your code works perfectly for me Thanks for the help :) usandfriends yours works also. Thank you both
closed account (3TXyhbRD)
Anytime.
closed account (18hRX9L8)
No Problem
Topic archived. No new replies allowed.