linux - C: Segmentation Fault when reading from a file -


i started working on project, , i'm having trouble reading things global variable. it's practice pthreads, why i'm using global variable in first place. program supposed read in numbers file represent solved sudoku puzzle, , text file formatted 9 number characters followed new line, 9 times. i've made sure that, when running program, file formatted such. know segment of code contains segmentation fault, can't tell where. can presume has fgets(). however, none of resources looked have in them make me think i'm using incorrectly. when resort using fgetc, reading in 1 bit @ time, making accomodations fgetc returning int, unlike fgets assigning string variable (in case, s).

i wouldn't bring stack overflow unless sure couldn't find it; i've been combing on code hour trying find seg fault, , doesn't make sense me. know seg fault here because directly after it, should print out entire puzzle matrix, doesn't make far.

int main(int argc, char *argv[]) {      file* puzzlefile;     char s[10];     int i=0, j=0, skip;     //open file passed in via command line     puzzlefile = fopen(argv[1], "r");      (i=0; i<9; i++){         //get first string of 10 characters         fgets(s,10, puzzlefile);         (j=0; j<9; i++){             //read numbers s puzzle 2d             //array, takes ints. ignore 10th             //character, \n             puzzle[j][i] = (int)(s[j]-'0');         }     }     ... } 

your problem seems this:

  (j=0; j<9; i++)                  ^^^  

this should j++, not i++


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -