subject

Add the following functions to the code:
oddsOnly - this function takes a string as an argument and it modifies this string in place (it does not return with the return statement) so that it deletes all characters that occupied even positions in the original string by shifting the characters that originally occupied odd positions. For example, if "hello there" were a parameter, then the updated string after the call to this function in the calling block would contain: "el hr". Don’t forget about the null character at the end of C strings and that strings in C could be simply treated as arrays of characters. Test this function by calling it from main.
Once the program runs properly, check for memory leaks and memory errors with Valgrind and apply more fixes, as needed
#include
#include
#include

char* repeated (char* original, int n);

int main(void) {

char *str = repeated("bon", 2);
printf("%s\n", str);
free(str);

char *str = repeated("bon", 3);
printf("%s\n", str);
free(str);

char *str = repeated("bon", 4);
printf("%s\n", str);
free(str);

return 0;

}

char* repeated (char* original, int n) {

int i, length = strlen(original);

char* newString = malloc (sizeof(char) * length * n + 1);

char* helper = newString;

for (i = 0; i < n; i++) {

strcpy( helper, original);

helper = helper + length;

}

return newString;

}

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, shadow56
Formula that contains a nested function that first calculates the average of the values in range e6: p6 and uses the round function to round that average to the nearest 10 dollars. use -1 for the value of the number digit argument. would the formula be =round(average(e6: p6),0
Answers: 1
image
Computers and Technology, 22.06.2019 22:20, kaiyerecampbell95
Pp 4.1 design and implement a class called sphere that contains instance data that represents the sphere’s diameter. define the sphere constructor to accept and initialize the diameter and include getter and setter methods for the diameter. include methods that calculate and return the volume and surface area of the sphere (see pp 3.5 for the formulas). include a tostring method that returns a one-line description of the sphere. create a driver class called multisphere, whose main method instantiates and updates several sphere objects.
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, issacurlyheadka
A. in packet tracer, only the server-pt device can act as a server. desktop or laptop pcs cannot act as a server. based on your studies so far, explain the client-server model.
Answers: 2
image
Computers and Technology, 24.06.2019 07:00, erick7123
Why do we mark tlc plates with pencil and not with pen
Answers: 2
You know the right answer?
Add the following functions to the code:
oddsOnly - this function takes a string as an argumen...

Questions in other subjects:

Konu
Mathematics, 28.10.2020 15:30
Konu
English, 28.10.2020 15:30
Konu
English, 28.10.2020 15:30