Segmentation fault in C, can't seem to find the cause -
I can not find the reason for the segmentation fault in the code given below (code) With the code in the line crashes, I saw this code with GDB, and it seems that everything is fine, within the evaluation of the function - the output is correctly filled, though I return after returning to the main memory Can not reach anything in. "PJ" returns a memory missing error in GDB, as if trying to print any other variable I checked that there were probably many values in the stack, but the stack size did not increase.
The crazy thing is that I can solve this error, but I do not know why it changes anything. If I add, anywhere in the evaluation (), an int declaration (such as Evaluate the function: (I have removed the part of the code, otherwise this would be a long way) main function: First of all you should see that at least two arguments are There may also be a segmentation fault. You can also do this I think segfault can avoid using this on one of two announcements. int iAmNotUsedEver; ), then the code is not always the cause of a split error and works perfectly in gdb Edit: Dynamically assign node [116] (
int * node = malloc (116 * size); also resolves the problem, but then I do not know why?
zero evaluation (int * parameter, integer output [] [16]) {int node [116]; node [0] = 0; output [0] [0] =! Node [0]; node [ 1] = parameter [0]; Output [0] [1] =! Node [1]; Output [0] [2] =! Node [0]; ... node [34] =! Node [114] Amp; amp;! Node [45]; node [45] =! Node [34] & amp; amp;! Node [105]; output [11] [15] = node [45];} < / Pre>
int main (int argc, char * argv []) {int i; int j; int k; int rate; integer parameter [8]; Int output [12] [16]; FILE * paramFile; file * outfile; paragraph = FOPN (RGR [1], "R"); If (paramFile == NULL) {printf ("I can not open the parameter file. \ N"); Exit (0); } OutFile = fopen (argv [2], "now"); If (outFile == NULL) {printf ("Something went wrong with output file. \ N"); Exit (0); } While (1) {for (i = 0; i & lt; 8; i ++) {ret = fscanf (paramFile, "% d", and parameter [i]); Printf ("Parameter:% d \ n", Parameter [i]); } If (ret! = 1) {break; } For (j = 0; j & lt; 12; j ++) {for (k = 0; k & lt; 16; k ++) {output [j] [k] = 2; }} Evaluation (parameter, output); Printf ("has been evaluated. \ T% d \ n", i); For (J = 0; J & lt; 12; J ++) {// For SEG fault here (k = 0; k
if (argc & lt; 3) return -1; After that, in the evaluation, as they are fixed array, you must pass in the parameter
zero evaluation (integer parameter [8], int Output [12] [16]) {...}
zero evaluation (int * parameter, int ** Output) {.. ..}
Comments
Post a Comment