c - Passing char arrays to a function -
the dreaded warning: passing argument 1 of ... makes integer pointer without cast
i don't understand this. trying pass simple string (yes, know character array) function. function parses string , returns first part. can please show me doing wrong? thank you!
char* get_request_type(char* buffer) { char* p; p = strtok(buffer, "|"); return p; } int main() { char buffer[30] = "test|something"; fprintf(stdout, "buffer: %s\n", buffer); //<-- looks great needs parsing char* request_type = get_request_type(buffer); //<-- error here fprintf(stdout, "%s\n", request_type); //<--expecting see 'test' }
there may yet come day when comfortable working strings in c, day not day...
you didn't include string.h
, compiler assume strtok
defined as:
int strtok();
returns int
, takes unknown number of arguments, it's call implicit function declaration. solution include string.h
strtok
declared.
Comments
Post a Comment