I'm attempting to remove a character from a string in C. The problem I am having with my code is that it removes the first instance of the character from the string but also wipes everything after that character in the string too. For example, removing 'l' from 'hello' prints 'he' rather than 'heo'
int i;
char str1[30] = "Hello", *ptr1, c = 'l';
ptr1 = str1;
for (i=0; i<strlen(str1); i++)
{
if (*ptr1 == c) *ptr1 = 0;
printf("%c\n", *ptr1);
ptr1++;
}
I need to use pointers for this and would like to keep it as simple as possible since I'm a beginner in C. Thanks