Jeff C.

asked • 05/04/21

UNDER NO CIRCUMSTANCES ARE YOU ALLOWED TO WRITE A SINGLE LOOP!

Simply call on the program, give it one or more parameters and press enter.

The conversion for that specific number should then be displayed unless no arguments were given. If by chance you do not provide the program with any arguments, then the program should display a user prompt, prompting the user to enter a decimal number.

UNDER NO CIRCUMSTANCES ARE YOU ALLOWED TO WRITE A SINGLE LOOP!

So, how would we approach such task?

Recall the structure of your typical C code:

#include <stdio.h>
/* comment. */
int main(int argc, char *argv[])
{
// comment
printf("Hello world")
return 0;
}

Note that main is a function but it takes some arguments.

int main ( int argc, char *argv[] )

These arguments are information about a string which you can pass whenever you run your program.

First, compile your code:

gcc -o Aassign1 Assignment1.c

Then pass in the arguments whenever you execute it

./Aassign1 arg1 agr2....

What do I want?

I need you to write a program that takes in n arguments but requires at least 3 arguments.

  1. The first argument should be the base in which you are providing the numbers in.
  2. The second arguments should be the base you want to convert to.
  3. The third, fourth, and all the way up to n is a sequence of numbers that need to be converted 
 ./Aassign1 decimal binary 1 2 3 4 5 6 7 8 9 10

Loops

YOU UNDER NO CIRCUMSTANCES ARE ALLOWED TO WRITE A SINGLE LOOP!

Bases to cover:

I want you to be able to be able to convert numbers back and forth from Decimal, Hex, and binary.

The structure of your code:

I would like you to write 9 functions that don't change their input (helper functions can) for converting between bases. this means you will need to use malloc to return a 2d array of the result:

char ** decimalToDecimal (...)
char ** decimalToBinary (...)
char ** decimalToHex (...)

char ** binaryToDecimal (...)
char ** binaryToBinary (...)
char ** binaryToHex (...)
char ** hexToDecimal (...)
char ** hexToBinary (...)
char ** hexToHex (...)

void seekUserInput (...)

void freememory(....)

int main (...)

1 Expert Answer

By:

Patrick B. answered • 05/05/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.