need help with struct and parameter

I can get my code run without using struct but my professor required me to use struct to get full credit. I have no idea how. Also, how do I print void displayUsage() if parameter is -h only?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include "unistd.h"
using namespace std;

// Global settings
struct global_args_t {
    // TODO
} global_args;

void displayUsage(){
	// Displays how to use this program
	// TODO
}

int main(int argc, char **argv){
	string name = "World";
        int time = -1; 
	int opt = 0;
	extern char *optarg;
	static const char* opt_string = "n:t:";
	opt = getopt( argc, argv, opt_string);
	while(opt != -1){  // While there are parameters to parse, do so
		switch(opt){
			case 'n':
				name = optarg;
				break;
			case 't': 
				time = atoi(optarg);
                                break;
			default:
				displayUsage();
				return 0;
		}
		opt = getopt( argc, argv, opt_string);	// Pull the next parameter, or 0 if none.
	}
if(time != -1){
    for(int i = 1; i <= time; i++){
      cout << "[" <<i<< "] Hello " << name << "!" <<endl;}
  }else{
      cout << "Hello " << name << "!"<<endl;
  }
  
      
	return 0;
}
Topic archived. No new replies allowed.