I am having a problem with the following code and I cannot figure it out? If anyone has any ideas, please let me know.
I have two global variables:
char *newArgv[100], *s[MAXCHAR];
and one function
getword(char *w)
in my main function, I make a call to this function by saying
getword(s[num]);
and in the getword function, I have an assignment that says something like
w[index] = 'e';
The problem is in that last line of code. The project compiles (obviously) but the program crashes. Anyone have any ideas why? Thanks!
You’re dereferencing a NULL pointer.
sis an array ofMAXCHARNULL pointers.s[num]returns thenumth pointer – which is also NULL. So insidegetword,w[index]is illegal.You’ll need to allocate memory dynamically: