Ancient Dragon was helpful in a way to parse argv(). It brought to mind
a method that suggested to me a way to look at the prefix after finding the expected string. For example (as I interpret it) if you are looking for a prefixed command it could be a command or it might something else like a file name. So for example if a command you are looking at is "key" and it comes in as "-key" then if you detect the word "key" you might check to see if the previous character was "-". In the following
code as a kind of example suggests a way to do this:
// tesstrcmp.cpp : Defines the entry point for the console application.
//
// ArgParse: an entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#define STRINGSIZE 128
int main(int argc, char *argv[])
{
// char ch;
// char *str;
int c = 1;
while (c < argc) {
printf("arg %i - |%s|\n",c,argv[c]);
if (argv[c][0] == '-') {
printf("|%c|\n", argv[c][0]);
// then show what it is
// assume the option string immediately
// follows the - symbol
if( strcmp( &argv[c][1], "key" ))
{
printf("%s\n", &argv[c][1]);
}
}
c++;
}
system("PAUSE");
}
This code will print out the "-" if it precedes the string "key". If "key" was typed and the preceding character was not "-" then using
some similar code, one could determine that the word "key" should probably be treated as a file name or some other case.
Just some random thoughts.
Thanks Ancient Dragon!
Cheers