Array assignments and Command line arguments

I have a file that I am working with that I have pass into my program through command line arguments. I don't want to touch the file, just want to store a temp of the file then after fixing the temp place it back in the original. After running the program it works but I keep getting an error message about my variable "filename". I know it has something to do with the way I assigned filename and argv[1]. I was looking into other ways of copying it, such as deep coping but I am not really dealing with pointers. I don't know if I need a for loop. I'm just moving the content of argv[1] ( the argument to a temp space then placing it back. real simple I know but idk where I'm stuck. Thank you in advance

do
{
in1.open(argv[1], ios::binary);
if (!in1)
cout << "That is not a valid file. Try again!\n";
} while (!in1);

interesting loop. Try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, ... You might want to rethink that.

After running the program it works but I keep getting an error message about my variable "filename".

Well, then something is wrong. Give us the info we need to understand the what "an error message" might mean. I can think of 5-10 things.

do
{
in1.open(argv[1], ios::binary);
if (!in1)
cout << "That is not a valid file. Try again!\n";
} while (!in1);

interesting loop. Try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, try to open the file named in argv[1]. If it doesn't open, ... You might want to rethink that.

Well, then something is wrong. Give us the info we need to understand the what "an error message" might mean. I can think of 5-10 things.

Yea, I passed in a file through the command line, just a simple .txt file which is set at argv[1]. Once it opens it is to creat a temp location to save the .txt file being passed in. Then it has a set of things to do in the function fixfile, which is does. It's to transfer everything over back to the original which is not doing. My question is do you think there is an error with the way that I am assigning filename and argv[1] or is there another way I should assign it

Ok, when I originally started this program it was more user friendly so I made into a do-while loop so that it would tell the usere everytime they typed in an invalid file. Because it is command line being passed in I don't need the do while loop.

I placed everything in an if statement but I am still having error with the variable filename. Any suggestions?? My problems are string copy lines. There must be another way to save the original in a temp, edit the temp, place it back into the original then delete the temp

You lengthen filename but you don't know how much space there is reserved for argv[1].
What you're doing is extremely dangerous for you must assume that there is no extra 'room' for the additional chars you're appending. This is probably the reason for your error.

I know it has to do with the way I an assigning filename and argv. argv is a pointer...

Yes it is.

... and filnaame is an array. I might be using the wrong type for the filename

No it's not. char *filename = new char [100]; defines a pointer that gets the address of a character array created from the heap. Why are you doing this? Why not just char filename[100]; :icon_question:

No it's not. char *filename = new char [100]; defines a pointer that gets the address of a character array created from the heap. Why are you doing this? Why not just char filename[100]; :icon_question:

I was doing that before but kept ketti conversion error saying I can not convert char* to char 100;

You lengthen filename but you don't know how much space there is reserved for argv[1].
What you're doing is extremely dangerous for you must assume that there is no extra 'room' for the additional chars you're appending. This is probably the reason for your error.

Yea I know, I'm just playing around with different ways to go about this. I have no clue how to create a temp location just to save the argv[1];

I call the filename through the comand line, My programs then checks the content of that file character by charcter to check the hex charcters. I was thinking saving the argument as a gobal variable then working with that instead but idk

So you only need to read argv[]. You only need it to open the file. After that forget about the name. If you should need the filename later in the program just store it in a variable of your choice and use that.

So you only need to read argv[]. You only need it to open the file. After that forget about the name. If you should need the filename later in the program just store it in a variable of your choice and use that.

Thank you so much for all your work, this is exactly how I started my program out. I am back to getting the error saying "Degbug Run Time Failure #2 start around the variable filename was corrupted Abort"

WaltP explained it twice before: Since we neither see your current code nor the concrete error message all we could do is guessing.
Guessing only tends to add even more confusion on your side.
On either side actually...

WaltP explained it twice before: Since we neither see your current code nor the concrete error message all we could do is guessing.
Guessing only tends to add even more confusion on your side.
On either side actually...

Thank you two for all of your help. I figured it out. i needed to dynamically allocate memory space for filename. Also there are functions called rename () and remove() in the stdio.h library which did the job