In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of April 7th
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #05 exercise sheet]
In this problem you should submit a file containing the function as described (without any main function). Inside the function do not print anything that was not asked!
In the shadowed halls of King’s Landing, power is everything - but wit and skill are the sharpest weapons. You are a humble coder seeking favor from Tyrion Lannister, the sharp-tongued and brilliant Hand of the King. He has no time for fools but admires those who can solve problems quickly and efficiently.
One night, over a glass of wine, Tyrion presents you with a challenge:
"A wise man once said: words are wind - but only if you remove the nonsense. Clean this message for me, and perhaps you’ll prove worthy of my trust."
Write a function void remove_all(char ch, char str[]) that, given a character ch and string str, changes the string str by removing all occurrences of ch.
For example, without the character 's', the word "westeroos" becomes "wetero".
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |str| < 100 | Length of the string |
You can also be assured that all characters in the string are lowercase letters.
You should submit a .c
file containing the requested function, without any main function and without printing anything. You can however create additional methods, if you need them.
Mooshak will use the following code to link to your function, read the inputs and call your method, printing its result.
#include <stdio.h> #define MAX_SIZE 100 void remove_all(char, char []); int main(void) { // Read amount of cases int n; scanf("%d", &n); // Read n cases and for each call the remove_all function char ch[MAX_SIZE], str[MAX_SIZE]; for (int i=0; i<n; i++) { scanf("%s %s", ch, str); printf("remove_all('%c', \"%s\") -> ", ch[0], str); remove_all(ch[0], str); // call function printf("\"%s\"\n", str); // show resulting string } return 0; }
Example Input | Example Output |
4 s westeros p stark n dragonstone a abracadabra |
remove_all('s', "westeros") -> "wetero" remove_all('p', "stark") -> "stark" remove_all('n', "dragonstone") -> "dragostoe" remove_all('a', "abracadabra") -> "brcdbr" |