Is it the correct way of allocating memory to a char*.
char* sides =\"5\";
char* tempSides;
tempSides = (char*)malloc(strlen(inSides) * sizeof(char));
Note that:
char *
;So that would be:
char *tempSides = malloc(strlen(inSides) + 1);
Still, if you want to duplicate the contents of inSides
, you can use strdup
, e.g.:
char *tempSides = strdup(inSides);
if (tempSides != NULL) {
// do whatever you want...
free(tempSides);
}