So I have a program, which helps me finding a cycles in graph by adjacency matrix. I have done everything, except output.
Realization
So, upon clicking exectute button, from masked edit control, an number up to 99 taken to for making a size of some arrays. Then I am creating 2d array **arr to fill it with zeros, and after that via for I fill info from text written in normal edit control. After this step I fill vector with edges from that array and doing DFS for that graph.
Now about problem
Like I said, I have 2d array. The whole procedure of filling it with zeros:
int **arr;
arr = new int* [x];
for (int i = 0; i < x; i++)
{
arr[i] = new int[x];
}
for (int i = 0; i < x; i++)
{
for (int j = 0; j < x; j++)
{
arr[i][j] = 0;
}
}
And with the next procedure (taking adjacency matrix from edit control) lies the warning #1:
int i = 0, j;
int lpos = 0;
for (CString line = s.Tokenize(_T("\r\n"), lpos); lpos > 0; line = s.Tokenize(_T("\r\n"), lpos))
{
j = 0;
int cpos = 0;
for (CString cell = line.Tokenize(_T(" "), cpos); cpos > 0; cell = line.Tokenize(_T(" "), cpos))
{
int num;
num = _wtoi(cell);
arr[i][j] = num;
j++;
}
i++;
}
Warning C6386 Buffer overrun while writing to 'arr[i]': the writable size is 'x*4' bytes, but '8' bytes might be written.
And before making output, I also put in another vector cycles and it also has warning #2:
for (int i = 1; i <= edges; i++) {
if (mark[i] != 0) {
int k = mark[i];
cycles[k].push_back(i);
}
}
Warning C6385 Reading invalid data from 'mark': the readable size is 'x*4' bytes, but '8' bytes may be read.
The problem is, when I tested output (adjacency matrix 7x7, all filled with 1), it catches an exception for those 2 pieces, which is being warnings. The exceptions is: Exception thrown at 0x00007FF6DD63AD7A in CTabControl.exe: 0xC0000005: Access violation writing location 0x00000000FDFDFDFD.
What I tried
For now, I tried to use make_unique pointer as an alterative for *
pointer on mark, which was declared previously like this: int *mark = new int[x];
(changed to auto mark = make_unique<int[]>(x);
). After change, there is a new error appear:
E0413 no suitable conversion function from "std::unique_ptr<int [], std::default_delete<int []>>" to "int *" exists
It points out to the function, where I use mark array: dfs_cycle(1, 0, color, mark, par, cyclenumber);
The function declared like this:
void dfs_cycle(int u, int p, int color[], int mark[], int par[], int& cyclenumber)
{
// ........
}
What can I do here to fix that?
EDIT
I think I found the problem, yet for now I can't find a solution. So, when the text is being read from text box, where adjacency matrix is, I am filling up the array with the contents of tokenized text. Here's how I am doing it:
int i = 0, j; int lpos = 0;
for (CString line = s.Tokenize(_T("\r\n"), lpos); lpos > 0; line = s.Tokenize(_T("\r\n"), lpos)){
j = 0;
int cpos = 0;
for (CString cell = line.Tokenize(_T(" "), cpos); cpos > 0; cell = line.Tokenize(_T(" "), cpos))
{
int num;
num = _wtoi(cell);
arr[i][j] = num;
j++;
}
i++;
}
When I try to make arr a 2d vector, I stumbled upon "out of range" error. So, that means I have to somehow tokenize my text and put it in array. I haven't figured out how.
User contributions licensed under CC BY-SA 3.0