Hi, I'm newish to C++ programming (As you may have guessed), and I'm trying to write a program that will run if its given command line arguments (Oddly enough, that part works) or if it's just activated, it will work (Where I'm having the problem)
I seem to have hit a wall though. I've tried a couple different ways of getting input, and no matter what I do, it seems that I get a segmentation fault whenever the program is just run without any command line arguments.
I'm not exactly clear as to what that means, from what I read, it means that the program is attempting to access read-only memory. I've been messing around with my declarations and handling of those variables, but I've run out of ideas to work around the violation (As I'm not sure exactly how it's happening.)
These are the relevant declarations:
1 2 3 4
|
int tempchoice;
char * oldfile;
char * newfile;
string newerworkaround;
|
And here is where the access violation appears to be occuring:
1 2 3 4 5 6 7 8
|
cout<<"\nPlease enter the filename of the file to change: ";
getline(cin, newerworkaround);
strcpy(oldfile, newerworkaround.c_str());
newerworkaround.clear();
cout<<"\nPlease enter the new filename: ";
getline(cin, newerworkaround);
strcpy(newfile, newerworkaround.c_str());
chkargs[2] = 1;
|
Any ideas would be immensely helpful. Thanks in advance.
-Tyler