pointers - cannot convert arg from char to const char in c -
void squeeze(char str[], char c) { char newstr[150]; int len = strlen(str); char *new_ptr; new_ptr = newstr; (int = 0; < len; i++) { if (str[i]!=c) *new_ptr=str[i]; new_ptr++; } printf("the string without character %c is: %s", c, newstr); }
i tried run code, showing error
int strcmp(const char*,const char*); cannot convert arg char const char
i know in strcmp
prototype, both args passed should of const char
, dont know how str[i]
can changed constant, modify code accordingly.
tried create char variable temp
hold str[i]
, isn't working either.
im new pointers, im not sure if im doing correct. can pls help?
try this
void squeeze(char str[], char c) { char newstr[150]; int len = strlen(str); char *new_ptr; new_ptr = newstr; (int = 0; < len; i++) { if (str[i]!=c) *new_ptr++ = str[i]; } *new_ptr = '\0'; printf("the string without character %c is: %s", c, newstr); }
Comments
Post a Comment