Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. Here\'s a C program. Please document where indicated. In particular, explain

ID: 3627274 • Letter: 7

Question

7. Here's a C program. Please document where indicated. In particular, explain how
each pointer expression (e.g., p[i] is a pointer expression, as is *ptr++)
works.

#include <stdio.h>
#include <ctype.h> /* for isalpha, which tests whether an character code is
for an alphabetic character */

const int n = 60;

/* document */
int comp(const void* v1, const void* v2) {
return (*(const unsigned char*) v2) - (*(const unsigned char*) v1);
}

/* document */
void dump(unsigned char* p, unsigned int n) {
unsigned int i;
for (i = 0; i < n; i++) printf("%c ", p[i]);
printf(" ");
}

int main() {
/* 'A' is 65 in either ASCII or Unicode.
The ASCII codes are, in fact, preserved in Unicode.
For the uppercase letters, the codes are consecutive.
*/
unsigned char c = 'A';
unsigned int n = 'Z' - 'A' + 1;

/* these two statements are equivalent to a single calloc
statement. From the documentation on calloc, figure out
what the appropriate calloc statement would be and
replace these two with the appropriate calloc statement. */
unsigned char* ptr = malloc(2 * n);
bzero(ptr, n);
unsigned char* base = ptr;

/* document from here until the end: give the output as well */
while (isalpha(c))
*ptr++ = c++;

unsigned int k = n / 2;
unsigned char* p1 = malloc(k);
unsigned char* p2 = malloc(k);
memcpy(p1, base, k);
memcpy(p2, base + k, k);
qsort(p1, k, 1, comp);
qsort(p2, k, 1, comp);

dump(p1, k);
dump(p2, k);

return 0;
}

Explanation / Answer

DEAR FRIEND here is the program and it was missing some header files which i added and documented the rest of the program if u have any problems understanding the program documntation or a specfic qestion i didn`t answer just message me PLEASE RATE #include /* for isalpha, which tests whether an character code is for an alphabetic character */ #include //for malloc() and qsort() functions #include //for memcpy()in the functions #include void bzero (unsigned char *to, int count) { while (count-- > 0) { *to++ = 0; } } const int n = 60; /* document */ int comp(const void* v1, const void* v2) { return (*(const unsigned char*) v2) - (*(const unsigned char*) v1); } /* document */ void dump(unsigned char* p, unsigned int n) { unsigned int i; for (i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote