I am expecting names from the command line and I need to hold them in an array. The multiple ways I've tried aren't working (I'm using strcpy) and I'm getting the following valgrind errors:
Use of uninitialised value of size 8
==23027== at 0x4C2E1E0: strcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23027== by 0x400F90: main (pt-cruisers.c:52)
==23027==
==23027== Invalid write of size 1
==23027== at 0x4C2E1E0: strcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23027== by 0x400F90: main (pt-cruisers.c:52)
==23027== Address 0x0 is not stack'd, malloc'd or (recently) free'd
Here's the code snippet:
char *racern[argc][20];
Racer *racers[argc];
pthread_t threads[argc];
int rc;
void *returnv;
for(int i = 1; i < argc; i++){
strcpy(racern[i-1], argv[i]); <-line 52
}
I know that the length of the names will not exceed 20 characters. I used argc to know how many names are going to be on the command line. I'm assuming I'm not giving enough memory however even when I gave a large arbitrary amount and tested with 3 names I still got the same issues. Any help is appreciated!