casting - Warning in C: assignment makes integer from pointer without a cast -
i keep getting error when compiling program. small part of code, if needed provide rest of code. ideas on why occuring?
void strip_quotes(char s[]) { if (s[0]=='"') s=s+1; if (s[strlen(s)-2]=='"') s[strlen(s)-2]=null; }
as dave has correctly pointed out reason compiler error:
s[strlen(s)-2]=null; /* = (void*)0 */
there bug in code won't cause compiler error:
if (s[0]=='"') s=s+1;
the increment of s
not visible caller, c passes value including pointers (see http://c-faq.com/ptrs/passptrinit.html). options correcting:
- shift content of array left using
memmove()
(or other copy mechanism) - pass address of pointer (a
char**
) - return pointer
s
changing content of s
preferable avoids possible problem if array dynamically allocated: pointers returned malloc()
(or calloc()
, realloc()
) can passed free()
. if value of s
changed cannot free()
d via s
.
note that:
void strip_quotes(char s[]) {
is equivalent:
void strip_quotes(char* s) {
incase confused pointers used in code.
Comments
Post a Comment