Skip to content
Advertisement

Valgrind message: Conditional jump or move depends on uninitialised value(s) unresolved

I’m trying a new assignment I’ve got: I need to copy the Environment variables from the shell into an array, then lowercase them and print them back. (I’m using Ubuntu 20.04.4 LTS, gcc for compiling, and writing my code in C language). I was advised to use malloc to create the array but decided not to. everything goes good up to the point I’m trying, for my own reasons, to see what I’ve created. then, when running it via valgrind – I’m getting this error I’m not quite sure why and how to fix. I’d appreciate the help.

as for the code:

JavaScript

as for the errors:

JavaScript

Advertisement

Answer

In PrintString you’re not using the right loop control:

JavaScript

You pass int counter which tells you how many entries you have, but you don’t use it. You instead look for a NULL entry, but you never set a NULL entry nor do you allocate space in the array for it.

So use counter instead.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement