Computer Systems I Laboratory Exercise 2



CSCI 247 Computer Systems I
Laboratory Exercise 2
1) Get more familiar with string and integer manipulation in C
2) Learn the Modulus operator and use it to for Base conversion
Submitting Your Work
Submit your C program files as the Lab Exercise 2 Submission item on the course web site. You must submit your
program by 2:00pm on the Monday following your scheduled lab session.
Lab Tasks
Task 1: Implement the “itoa” function
Implement a function with the following function signature:
char* itoa(int num, char* str, int base);
where “num” is an integer that you need to represent as a string in the “base” specified.
For the purpose of this exercise, you can assume that the string pointer passed in points to a buffer of adequate
1) Consider how the number “0” will need to be handled first
2) If the base is “10” and the number if negative, convert the number to a positive number, but keep track of
this with a flag
3) Get the least significant digit by finding the modulus of the number and the base.
4) Represent this digit in ASCII by either adding it to the ASCII ‘a’ or the ASCII ‘0’ and store it in a string
5) Divide the number by the base and repeat steps 3 to 5 until the number is reduced to zero
6) If the number was base 10 and negative, remember to add the ‘-‘ sign
7) Reverse the string and display


There are no reviews yet.

Be the first to review “Computer Systems I Laboratory Exercise 2”

Your email address will not be published.