Since we just had a fresh look at working with multiple modules, here’s a quick exercise to make…

Since we just had a fresh look at working with multiple modules, here’s a quick exercise to make it even more familiar for you! Write a program that prompts the user for an integer value and displays the value in base eight (octal) and base sixteen (hexadecimal):

Please enter a base ten integer: 59
The value in octal is 073
The value in hexadecimal is 0x3b

A very simple program, but we’ll complicate it a bit by splitting everything into multiple files. Here’s what you should write:

  • main.c — This gets the integer from the user and passes it as an argument to the DispOct and DispHex functions.

  • dispoct.c — This contains the implementation of the DispOct function, which receives an integer value from the caller and displays it to stdout in octal.

  • dispoct.h — This contains the prototype of the DispOct function.

  • disphex.c — This contains the implementation of the DispHex function, which receives an integer value from the caller and displays it to stdout in hexadecimal.

  • disphex.h — This contains the prototype of the DispHex function.

Once you’ve written the source code, you should build each module by hand one at a time using the -c switch with gcc. (Don’t forget to #include the header files into the appropriate .c files so that any function prototypes that are needed in any module are available!)

The commands to build the individual object files are:

  • gcc -c main.c
  • gcc -c dispoct.c
  • gcc -c disphex.c

Confirm that you have all three object files by producing a directory listing (i.e., ls -l). Then link all three object files together to produce a.out. (BTW, you don’t compile header files because they normally don’t contain any code that allocates space in memory, they only contain code that is information for the compiler.) Then you can link all three object files into a single executable with this command:

  • gcc main.o dispoct.o disphex.o

If all goes well, that should produce the final executable a.out, which you can then run from the command line as usual.

This program isn’t necessarily rocket science, I’m more interested in getting you closer to the build process, one file at a time to see how the pieces fit together. In the near future we’ll look at less tedious ways to handle multi-module projects. So leave all of your files in a directory named HW09 so I can collect them later.

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!