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 6 other people reading this forum.

 UWA week 36 (2nd semester, mid-semester break) ↓
SVG not supported

Login to reply

2:00pm Mon 5th Sep, Ethan HA.

> As the file values are written as strings, how do we convert these values to an int for our struct? I tried using sscanf and storing the formatted values in int values but there's a mismatch error. > For example, sscanf("%s", atoi(minute)); doesn't work when compiling.
This is something I think we have to figure out and code-for ourselves. I am not familiar with the usage of sscanf(), so I can't help with any formatting problems, and in fact I might be entirely misreading your problem here, however it seems to me that a big problem with this code is that not all of the file's values will be integers. Some will, but others will be strings (eg the abbreviations for the days and months "jan" "feb" etc.) and some could be characters, ie " * ". I don't know if there is a standard function that could correctly perform ALL of these conversions at once, so you'll need to write code to handle each of these cases for yourself. I'd suggest writing some functions like "month_convert()" that takes parameters of a string and returns an integer corresponding to the described month or to an invalid value. If sscanf() works how I think it does, you can maybe plug this function into sscanf() instead of atoi(), and maybe loop over the various forms the data could take. Personally, I wrote a sub-function using strcmp() and a while loop that checks if the supplied string (eg "tue") exists within a list of valid data values ("jan", "feb", "mar", ... ,"dec") and returns the index for the identical string in the list. Hopefully this will help. If you don't like these any of these methods, there are probably dozens of other ways to go about doing this, you'll just need to be creative enough to think of them. Take a step back, re-evaluate what you actually need to do, and work through it step-by-step. If you can't get a function to do what you want, write your own function instead!

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