I'm currently working on PSET6 and had a question for the parsing section. I decided to use strtok() and as a result, will need to malloc memory when creating new char*. How do i know how much memory to assign/ what would be a safe amount? I know I can set an arbitrarily large number, but how do i dynamically allocate it? Or is that needed? Below is the beginning part of my code.
Thanks a bunch!
char* copyLine = malloc(sizeof(char*) + 100); strcpy(copyLine,line); char* method = malloc(sizeof(char*) + 100); method = strtok(copyLine, " "); char* request_target = malloc(sizeof(char*) + 100); request_target= strtok(NULL, " "); char* HTTP_version = malloc(sizeof(char*) + 100); HTTP_version = strtok(NULL, " "); free(copyLine); free(method); free(request_target); free(HTTP_version);
So my question is specifically, what do i put inside malloc()/ how do i know how big to assign a char*.