We’re at war! The orcs are attacking and are looking very hungry! Look at them!
However, instead of simply killing you, these not so friendly looking beasts target vowels instead of bowels. So when speaking to, they munch and munch, stripping your carefully chosen words of all vowels. How rude. Implement a function called char* munch(char* sentence)
that obscures all vowels with an ‘X’, and then prints the results. You will also need a int main()
function.
Assume a maximum character length of 100 for the input sentence.
Tips:
scanf()
or fgets()
for user input? What is the difference? Look up how to use either functions.*
. A char array gets converted to a pointer if returned or given as an argument. Remember, in Java, the function signature would simply be char[] munch(char[] sentence)
my_nice_method
instead of Java’s camelcasing myNiceMethod
.INPUT: 'hello friendly green guys' OUTPUT: 'hXllX frXXndly grXXn gXys'
Start from this blueprint:
#include <stdio.h>
#include <stdlib.h>
char* munch(char* sentence) {
char* response = malloc(sizeof(char) * 100);
// TODO eat those vowels!
return response;
}
int main() {
char sentence[100];
// TODO read input
printf("INPUT: %s\n", sentence);
printf("OUTPUT: %s\n", munch(sentence));
}
The correct use of malloc()
will be explained in the coming labs.