The user types bits 110, or 6, and the program returns
the 6th input.

How do I get the program to scan in a binary and decimal value?

Recommended Answers

All 3 Replies

The user types text. Read text, as a string. Interpret the string how you choose. Maybe first check if it could be binary, if not, try decimal. The function strtol would be handy, methinks.

I've seen this extension to the language to handle binary constants...you might be able to incorporate it. Notice the number 0b111

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
	fprintf(stdout, "ans->%u\n", 0b111);
	exit(EXIT_SUCCESS);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.