Question: Consider the following snippet of code. (Assume that input strings, including null terminator, will always fit within the size 255 array.) char* to_upper_case(char* original) {
Consider the following snippet of code. (Assume that input strings, including null terminator, will always fit within the size 255 array.)
char* to_upper_case(char* original) { char capstr[255]; int i; for (i = 0; original[i] != '\0'; ++i) { if (original[i] >= 'a' && original[i] <= 'z') { capstr[i] = original[i] - (char)'a' + (char)'A'; } else { capstr[i] = original[i]; } } capstr[i] = '\0'; return capstr; } void main() { char* temp = to_upper_case("the c programming language"); //... (other lines of code) printf("%s", temp); } (a) What will be the possible output(s)? Trace this code manually, do not run it. (Hint: be careful!) [0.5 points]
(b) If there is strange output, why does the program give that output? Explain in terms of memory and pointer usage. [0.75 points]
(c) What change(s) can be made so that the program works as expected? [0.75 points]
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
