strcmp argument type error
I am trying not to use isSpace
function so the only thing came to mind is strcpy
but I am g开发者_如何学Cetting an error
while ( walker > 0 && strcmp(a[walker - 1],space_const) )
Warning 86: argument 1 conflicts with formal definition
Anyone know how to fix this issue? space_const
is a char
initialized as " "
char* strTrim(char* string)
{
char* a= string;
char delims[3];
char space_const[] =" ";
char syntax_const[]=" \t\n\v";
size_t walker = strlen ( a );
strcpy(delims,space_const);
/* Trim trailing spaces */
while ( walker > 0 && strcmp(a[walker - 1],space_const) )
--walker;
a[walker] = '\0';
/* Trim leading spaces */
walker = strspn ( a,syntax_const);
memmove ( a, a + walker, strlen ( a + walker ) + 1 );
return extractCmd(a ,space_const );
}
You are trying to compare a character (small integer) and a string.
char* a= string;
/*... */
strcmp(a[walker - 1], space_const);
^ character
strcmp
looks like this
int strcmp(const char *s1, const char *s2);
^ string ^ string
It's likely you want something like:
(a[walker - 1] == ' ' || a[walker - 1] == '\t' || ..)
You should write a function. but then you would end up rewriting isspace
.
Why can't you use isspace
in the first place ?
By adding brackets after the variable a[], you have made it a char. You must then dereference it back into a pointer using the ampersand &; Such as:
while ( walker > 0 && strnicmp(&a[walker - 1],space_const, strlen(space_const)) )
Be very careful here, it looks like this could be used for a buffer overflow since the passed in string is not being validated.
精彩评论