>>c--;
The initial value of c is too large. The value of argc is the number of strings in the array. So it counts from 0 to argc-1. You should make the loop as you would when using any other array
for(int i = 0; i < argc; i++)
{
// blabla
}
If you would rather use a while loop, then
int c = argc-1;
while( c )
{
}
Ancient Dragon
Achieved Level 70
32,274 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,590
Skill Endorsements: 70
why are you trying to assign an array of pointers (str) to a single string? Also you failed to heed my warning about argc. If you want to do anything useful you have to start from argv[1] to argv[argc-1], not the other way around. Western languages read from left to right, not the other way around, and that's the way they are represented in argv.
// ArgParse.cpp : Defines the entry point for the console application.
// How can you refer to a character in a string? This does not work !!!
#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( stramp( &argv[c][1], "Hello" )
{
printf("%s\n", &argv[c][1]);
}
}
c++;
}
system("PAUSE");
return 0;
}
Ancient Dragon
Achieved Level 70
32,274 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,590
Skill Endorsements: 70
Question Answered as of 1 Year Ago by
Ancient Dragon