c - Valgrind-Uninitialised value error with getline() function -


i want read multiple lines text file loop, conditional jump or move depends on uninitialised value(s) error in getline() line.

my code:

char *string; size_t len = 0;     while (getline(&string, &len, filestream) != -1) { // error happens line        //   }  free(string);    fclose(filesream);    

i tried failed fix it. solutions appreciated.

you need either of below.

  1. set char *string = null; , len 0. [[ preferred method ]]

  2. allocate memory char *string , send size of allocated memory using len.

related quotes man page referrence

   if *lineptr set null , *n set 0 before call,    getline() allocate buffer storing line.  buffer    should freed user program if getline() failed.     alternatively, before calling getline(), *lineptr can contain    pointer malloc(3)-allocated buffer *n bytes in size.  if    buffer not large enough hold line, getline() resizes    realloc(3), updating *lineptr , *n necessary. 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -