I'm not too sure how to troubleshoot or understand what could be happening, any help would be appreciated and if there is any clarification needed I would be more than happy to provide, Thanks!
CodePudding user response:
The string you're constructing in ran
doesn't have a terminating null byte, so atoi
will read past the bytes you've written into the ones you haven't (and possibly past the end of the array), which is what valgrind is telling you.
You'll need to manually terminate the string after reading the characters.
while(line[i] != ',') {
ran[k] = line[i];
i = i 1;
k = k 1;
}
ran[k] = 0;