I want to delete vowels from a string and print the remaining. But my if condition doesn't behave as expected.
#include <stdio.h>
void filter (char *p, char *q)
{
while (*p != '\0')
{
if (*p != 'a' || *p != 'e' || *p != 'i' || *p != 'o' || *p != 'u')
{
*q = *p;
q++;
}
p++;
}
*q = '\0';
}
int main ()
{
char str1[10] = "hello";
char str2[10];
char *p, *q;
p = &str1[0];
q = &str2[0];
filter (p, q);
printf ("%s", str2);
return 0;
}
I expect the output to be hll but the output was hello. I would like to know the reason for the mistake and the way to fix it.
Aucun commentaire:
Enregistrer un commentaire