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?
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include "unistd.h"
usingnamespace 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;
externchar *optarg;
staticconstchar* 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;
}