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

C programming questions requirements: You CANNOT call any library functions // 1

ID: 3666963 • Letter: C

Question

C programming questions
requirements: You CANNOT call any library functions

// 11. Write a function to convert an unsigned integer to a decimal string.

//     For example if the integer has decimal value 52 the string would be ?52?.

void myUInt2Str(unsigned int num, char* string) {

    // TODO: add your code here

    string=num;

    return string;

}

Explanation / Answer

char *ultostr(unsigned int value, char *ptr, int base) { unsigned int t = 0, res = 0; unsigned int tmp = value; int count = 0; if (NULL == ptr) { return NULL; } if (tmp == 0) { count++; } while(tmp > 0) { tmp = tmp/base; count++; } ptr += count; *ptr = ''; do { res = value - base * (t = value / base); if (res < 10) { * -- ptr = '0' + res; } else if ((res >= 10) && (res < 16)) { * --ptr = 'A' - 10 + res; } } while ((value = t) != 0); return(ptr); }