This one is a mess. You need to allocate a string - you cannot just say char *out = "". char *out = "" set's char pointing to an empty string, in possibly read only memory! (It should really be const char *out = "", but that does us no good since we want to modify out.) Allocate memory for the string.
Once you get it functional, then:
Make your call to strlen() outside the loop - otherwise, you may be taking a string length each time you loop - which is not needed.
Keep track of the end of the string yourself, and you can avoid the strcat() inside the loop. (Again, calling strcat each time will make the running time of the function O(n^2). This function should be O(n) when you're done.)

Your allocated array has length n which means a valid index from 0 through n-1. In your loop, i goes from 0 and stops once it reaches n. You then attempt to use this value in i (which is n) to index the allocated array which is one past the allowable bounds (n-1). Short answer is you need to allocate an extra byte for the array to store the null.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens

That's a string of 6 characters (as returned by strlen) requiring 7 char's worth of memory.

Naturally you can count the vowels first and then allocate that much + one char for the null terminator, but there is nothing wrong if you use more memory for the string. E.g memory for the vowels in "string" might look like this:

7 bytes:i, \0, z, w, q, z, x

Who cares what garbage comes after the null terminator since you are not going to look at that.

Last edited by anon; 05-05-2009 at 05:06 PM.

I might be wrong.

Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.