Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with the following coding problem. It is to be written in C and compiled with the gcc compiler command. Please help, Thank

Please help me with the following coding problem. It is to be written in C and compiled with the gcc compiler command. Please help, Thank You! Can you post screenshots of your code and output instead of copying and pasting? It is easier to see the format.

Write a program bin.c that will take a binary numbers as input, and output the decimal equivalent. Build your program using the following steps:

a. Copy the below code to a new .c file called bin.c

#include

// hello world in C

int main(void) { printf("hello, world! ");

return 0; }

b. Modify the code, so that instead of outputting 'hello, world', it outputs the prompt symbol '>'

c. Modify the code so that it will read user input, and then simply print out the users input. You may want to use function fgets to get the user input.

d. modify bin.c so that it converts the input string into a number, and prints the number. Write the code to convert from binary to decimal yourself (dont use a library call, or code found on the internet).

e. Your code should respond to empty input with value 0, and should respond to invalid input with message input must contain only zeros and ones, and exit with value 1, indicating an error.

It should compile with the command gcc -o bin bin.c

Examples of how it should work are:

$ ./bin

> 1001

9

$ ./bin

> 11111111

255

$ ./bin

> hello

input must contain only zeros and ones

$ ./bin

> (no input given, just hit enter)

0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

4. Did you rethink your decision?

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago

Question

7. What traps should she avoid?

Answered: 1 week ago