Why are you using realloc()
at all? I don't see here any reason for dynamic allocation. Why can't you just process buffer
content?
In accordance to C99 standard:
7.19.7.2 The fgets function Synopsis
...
The fgets function reads at most one less than the number of characters specified by n from the stream pointed to by stream into the array pointed to by s. No additional characters are read after a new-line character (which is retained) or after end-of-file. A null character is written immediately after the last character read into the array.
Yet another point. Why so strange memcmp()
calls? From man memcmp
:
The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.
OK, finally (maybe) third. You check for space ('') inside
whole_entrie
to stop. But if you just enter command with '\n'
at the end you will copy it including '\n
' so strcmp()
will fail to check your command.