i get a segmentation fault (core dumped) error but only when half my code runs : the goal of this code is to manipulate an ASCII "image" that comes in the form of a really long string that i print out on different lines
.............
.............
.XXX.....X...
.XXX.....X...
.XXX.........
.XXX.........
.XXXXXXX.....
.XXXXXXX.....
.XXXXXXX.....
...........
it looks like this
`    #include <iostream>
    #include <iomanip>
    #include <algorithm>
    #include <fstream>
    #include <vector>
    #include <string>
    #include <cassert>
    
    int main (int argc, char* argv[]) {
	    std::fstream img(argv[1]);
	    std::vector<char> path;
	    char x;
	    while (img >> x) {
		    path.push_back(x);
	    }
	for (char i = 0; i < path.size(); ++i){
		if (i%13==0){
			std::cout << path[i] << std::endl;
		}
		else{
			std::cout << path[i];
		}
	}
	std::string replace = "replace";
	std::string dilation1 = "dilation";
	std::string erosion1 = "erosion";
	std::string floodfill1 = "floodfill";
	char old_char = argv[4][0];
	char new_char = argv[5][0];
	if (argv[3] == replace) {
		for (char n=0; n<path.size(); ++n){
			if(path[n]==old_char){
				path[n]=new_char;
			}
		}
			
	for (char i = 0; i < path.size(); ++i){
		if (i%13==0){
			std::cout << path[i] << std::endl;
		}
		else{
			std::cout << path[i];
		}
	}
	}
	if (argv[3] == dilation1) {
		std::cout << "this is ok" << std::endl;
	}
}`
here is my code
the replace part of the code is meant to take this as the input from the console


./image_processing.out input4.txt output4_replace.txt replace X O


and replace the X's with O's
and it works
but then i move onto the dilation function which takes this as input from the console


./image_processing.out input4.txt output4_dilation.txt dilation X


nevermind wat it does yet i havent even gotten that far because whenever i try to run the code with the second "if" statement i get this


.............
.............
.XXX.....X...
.XXX.....X...
.XXX.........
.XXX.........
.XXXXXXX.....
.XXXXXXX.....
.XXXXXXX.....
Segmentation fault (core dumped)

i dont know why it does this and i dont know why it only gets as far as the last line before it does that, when i comment out the second if statement the code runs fine however it only does replace