This:
char* commandLine = malloc(sizeof(strlen(line)));
is wrong. You shouldn't use sizeof
here, and certainly not on the result of calling strlen()
. The above is the same as:
char *commandLine = malloc(sizeof (size_t));
since the return type of strlen()
is size_t
. Thus, the actual strlen()
return value is ignored.
The proper code is:
char *commandLine = malloc(strlen(line) + 1);
since you must add 1 for the terminator, which is not included in the length returned by strlen()
.
There is no need for any sizeof
here, since you're very obviously working with characters.