Question
1. (15 points) Write a C function with the following signature that gets three strings as input parameters: char* str, char* pattern and char* altPattern
1. (15 points) Write a C function with the following signature that gets three strings as input parameters: char* str, char* pattern and char* altPattern. Your function should searches for pattern in str and replaces all occurrences of pattern by altPattern and return the resulting string as its return value.
Please note that the function should not modify the content of the three char arrays passed to it as its input parameters while doing the mentioned task.
Hint: you may use malloc function to allocate memory for storing the string that your function returns.
char* findAndReplace(char* str, char* pattern, char* altPattern){
...
}
2. (10 points) Write a function that gets a variable of type int as its only input parameter and prints out the binary representation of the input integer. Our assumption is that the input parameter is always a non-negative integer.
3. (15 points) Given the following structure for node, write a function that gets the pointer to the head of a singly linked list (type: node*) as its only input parameter and returns the average of values stored in the list (return value type: double).
struct node{
int value;
struct node* next;
};
typedef struct node node;
(Focus on #3)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started