Hello everyone!
I have posted something on this yesterday, I was hoping that finding the flow in part of the code would resolve the whole issue but I was wrong...
This is a program that reads a file and inputs integer values into a double vector.
The 2nd line of the file to be read has the number of clauses and the number of variables I will make use... The Idea is to insert specific values into a vector of dimensions: clause number by literal number...
I'm using command line to call the function
example
C:\folder\prog.exe file
Here is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char ** argv)
{
int numClause, numLit; //number of clauses, number of literals
int linecount = 0;
int spacecount_;
int varcount;
ofstream tempfile;
ifstream tempfile_;
string str;
int array[50][50];
vector< vector< int > > matrix;
ifstream inData;
inData.open(argv[1]);
while ( !inData.eof() )
{
getline (inData, str);
if (linecount == 1)
{
sscanf(str.data(), "p cnf %d %d", &numClause, &numLit);
vector< int > clause;
for (int j = 0; j < numLit; j++) clause.push_back(0);
for (int i = 0; i < numClause; i++) matrix.push_back(clause);
}
if (linecount > 1 && linecount < numClause)
{
spacecount_ = 0;
for(int i = 0; i != str.size(); i++) spacecount_ += ( str[i] == ' ');
varcount = spacecount_ + 1;
int *temp;
temp = new (nothrow) int [varcount
tempfile.open("fout.txt");
tempfile << str;
tempfile.close();
int number;
tempfile_.open("fout.txt");
for (int i = 0; i < varcount; i++) tempfile_ >> temp[i];
tempfile_.close();
for (int i = 0; i < varcount; i++)
{
int column = abs(temp[i]);
int row = linecount - 1;
int value = (temp[i] > 0 ? 1 : 2);
matrix[column][row] = value;
}
delete [] temp;
}
cout << str << endl;
linecount++;
}
inData.close();
return 0;
}
|
Algorithms is:
(1) open file to be read
(2) 2nd line contains info about dimensions... Initialize the double vector
(3) line 3 and on has the variables I want to process
(4) I am counting spaces to know how many variables there is in a line
(5) creating a 1d dynamic array to store variables
(6) process the variables
(7) inserting then into the vector in a specific way
(8) repeating from (1)
But for some reason the program seems to crash. I am perfectly sure that my algorithm works but I am obliged to use a double vector...
Any help would be much appreciated!