pointers - Set Char* to Trim of Char in C -
this question has answer here:
lets see example:
char var1[100] = "test "; char* var2;
if this:
var2 = &var1;
i'll spaces.
i want var2 trim of var1.
as far know there's no way of doing without changing original string or copying modified version of string new source.
as pm100 said, can find pointer pointing first instance of space in string, distance source pointer , pointer find index of whitespace. after doing so, use strncpy
copy portion of string new pointer. make sure allocate new pointer and put terminating character '\0' @ end.
the other solution use strchr again pm100 said, time change pointer points to '\0'.
Comments
Post a Comment