Question: Please write the code with C language 1. (60 pts) Write a function which can add any character to a specified index of a string.


Please write the code with C language
1. (60 pts) Write a function which can add any character to a specified index of a string. Function prototype must be as follows: void insertChar (char string[], char c, int index) string parameter: String which the function will add a character. c parameter: The character to be added to string. index parameter: The index which the function will insert the character. Notes: 1. insertChar function should not overwrite any characters. It should insert the new character and offset remaining characters by one index. 2. You can try your function with a complete code which gets a string, a character and an index from the user and show the result. But, only insertChar function is necessary and will be graded. 3. Only methods and functions we learned during the course should be used. Otherwise, it will not be graded. Example parameter sets with corresponding outputs: string index Result: Hello world ! 11 Hello world! Let's eat mom! 9 Let's eat, mom! I have to now k 10 I have to know I like cooking cats and dogs 14 I like cooking, cats and dogs 2. (40 pts) Now, using insertChar function you wrote in previous question, write a program which will get a sentence from user and, if there are comma(s) but no space(s) after them, will add a space after each comma and print the sentence as corrected, if there is no comma, print the sentence as it is. Notes: 1. Only methods and functions we learned during the course should be used. Otherwise, it will not be graded. Example inputs and outputs Input Output However, I have to leave now. However, I have to leave now. They are red and green, respectively. They are red and green, respectively. I like reading, swimming painting and walking. I like reading, swimming, painting and walking. Supplementary information (Not necessarily related with the homework): Question: How can I get rid of the new line character ( ') while using fgets function? Answer: You can replace new line character with null character (*\0'). See the example below. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
