PLEASE NOTE: the upgrades to this server,, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49


This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying selected article
Showing 1 of 919 articles.
Currently 5 other people reading this forum.

 UWA week 32 (2nd semester, week 3) ↓
SVG not supported

Login to reply

3:29pm Tue 9th Aug, Christopher M.

> 1. String/Char to int (e.g., '1234' to 123 or '9' to 9)
Hi. Firstly, let's make sure we're using the correct C syntax, else we may be chasing a solution that doesn't exist. Strings, sequences of zero-or-more characters, are represented between double-quotes, such as "1234". Single characters are represented between single-quotes, such as '9'. In the ASCII character set (see man ascii ) the digit/character '9' does not have the integer value of 9, and the digit/character '3' does not have the integer value of 3, BUT the difference between '9' and the integer 9, is the same as the difference between '3' and the integer 3. Have a look at the table from man ascii - look at the decimal values - and you'll see the values of '9', '3', etc. Most importantly, look at the integer value of '0'. Now, you want the difference between the characters '9' and '3' to be the same as the difference between 9 and 3 (and it is!) Got it yet?? Next, observe that the integer 'meaning' of the string "123" is 100 * magicfunction('1') + 10 * magicfunction('2') + 1 * magicfunction('3') by Horners' Rule. Just need to work out that magicfunction() ....
> 2. int to string/Char (e.g., 1234 to '1234' or 9 to '9') -> I've been trying to use itoa() for this, but it doesn't seem to work.
There is no itoa() function in the C library. We didn't quite get there this morning, but this page will help: [CITS2002]

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy