I'm working on a program to read input in from a file in c++. Each line starts with a number to determine the size of a two dimensional array. It is followed by a couple numbers to determine which row and column to change from a 0 to a 1, and finally print the array. However whenever I try to run the program I just end up with "segmentation fault(core dumped)." Any help with what I might be doing wrong here would be appreciated.
#include <stack>
#include <stdexcept>
#include <fstream>
#include <array>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <string>
using namespace std;
int main(int argc, char** argv)
{
if (argc < 3)
{
throw invalid_argument("Usage: ./hello <INPUT FILE> <OUTPUT FILE>");
}
ifstream input;
ofstream output;
input.open(argv[1]);
output.open(argv[2]);
string line;
char* com, *op;
while(getline(input, line))
{
com = strdup(line.c_str());
op = strtok(com, "\t");
int n = stoi(op);
int board[n][n]={{0}};
istringstream iss(line);
int a, b;
board[a][b] = 1;
if (!(iss >> a >> b))
{
break;
}
for (int i = 0; i<n; i++)
{
for (int j = 0; j<n; j++)
cout << " " << board[i][j] << " ";
printf("\n");
}
}
input.close();
output.close();
return 0;
}```