Wednesday, April 21, 2010

Lab and homework #16

1) A C-string, as opposed to a C++ string, is implemented
as a NULL-terminated array of characters. Thus, "hello" is 6 characters long, 'h', 'e', 'l', 'l', 'o', '\0'.
char s[6] = "hello";
Write a function stringlen which takes in a C-string and returns the string length of 5.
Write a function stringcopy which takes in two C-strings, source and destination, and makes destination = to source.
Write a function stringreverse which will reverse a C-string.

2) Write a function intToString which will take in a C-string and an integer, and write the digits of that number to the C-string.

3) Modify the above so that it takes in a 3rd parameter, which is the base. Passing in a 2 will make the string contain the number in binary. Passing in a 3 will make the string contain the number in ternary. Passing in a 10 will make the string contain the number in decimal.

No comments:

Post a Comment