Q:

Removing vowels from string

I've been trying to do this function where the target is to remove the vowels of a string. This is what I have :
void
take_vowels (char s[])
{
  int i;
  char r[4];

  for (i = 0; i <= strlen (s); i++)
    {
      if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o'
          || s[i] == 'u')
        {
          r[i] = ' ';
        }
      else
        {
          r[i] = s[i];
        }
    }
  printf ("%s\n", r);
}

int
main ()
{
  char s[4] = { 'a', 'e', 'k', };
  take_vowels (s);
  return 0;
}

This seems to work fine but I want to know if there is a better way to do this function. Any suggestions?

A:

Your title says 'remove vowels from the string', but in fact you are replacing the vowels by a space.
You don't need to do strlen at all. You just need to remember that your string is (by definition) already large enough, and it is a sequence of characters. Also a switch statement is nicer than a large if, and you presumably want to handle both cases.
It's also normal to take a char *s as an argument rather than a char s[]. Look at every string function in the standard library! Similarly, the normal way to initialize C strings is:
char *s = "aek";

not
char s[4] = { 'a', 'e', 'k', };

Here's two (untested) functions which will help:
#include <ctype.h>

...

void 
replacevowelsbyspace (char *s)
{
    for (; *s; s++)
    {
        switch (tolower (*s))
        {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                *s = ' ';
            default:
                break;
        }
    }
}

and
#include <ctype.h>

...

void 
deletevowels (char *s)
{
    char *d = s;
    for (; *s; s++)
    {
        switch (tolower (*s))
        {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                break;
            default:
                *d++ = *s;
        }
    }
    *d = 0;
}

