Hone Your Disk Drive C

Often times the problems you’ll encounter in C involve interface with something else. You’ll need to code directions for an operating system or interact with data that already exists or is output from some function. In this month’s exercise, you get to test-run those skills.

As an example, I’ve created a data file. Your job is to write code that properly reads the data from that file, and then outputs the data all formatted and pretty. If you’ve read my C programming books on file I/O, then this should be a relatively simple exercise, although it’s always good to practice.

The chunk of data has a format. In this case here are the “docs” for the format:

  • Node number (long int)
  • Gateway (20 character string)
  • Access Time (time_t value)

The name of the data file is 0914.dat and you can download it by right-clicking that link. I can promise you that the file isn’t malware, although that may not stop your computer’s anti-virus software from getting all freaky. The file is only 40 bytes long, and I don’t think any clever Bad Guy could shove malware into something that teensy.

If you read the data properly, the output lists these items:

 Node number: 98255171
     Gateway: wambooli.com
 Access Time: Mon Sep  1 16:46:11 2014

Please attempt to code your own solution before you peek at mine. Keep in mind that my solution is only one way to solve the problem; the C language is flexible enough that anyone can devise a proper (or improper) solution.

Exercise Solution