Posts

Showing posts with the label valgrind

Valgrind reports SIGSEGV and use of uninitialised value

Valgrind reports SIGSEGV and use of uninitialised value Edit: All valgrind errors where solved by initialising i . i I am working with strings; reading strings from a file, separating them using strsep() , converting them to int using atol() . My code compiles on gcc and runs without errors, but when checked with valgrind I get the error mentioned in the title. strsep() atol() I am trying populate a two-dimensional array grid[20][20] with int values from a text file. The text file contains lines of numbers separated by spaces, something like 20 81 65 07 54 72 13 28 66 95 00 20 00 84 06 30 85 43 15 73n grid[20][20] 20 81 65 07 54 72 13 28 66 95 00 20 00 84 06 30 85 43 15 73n My code, (excluding all of the file IO) is as below. (Note that I do handle the file correctly: checking the result of fopen , closing with fclose ). fopen fclose #include <stdio.h> #include <stdlib.h> #include <string.h> #define STR_LEN 20 #define NUM_LINES 20 #define MAX_SIZE 100 int ma...