0

problem is a little harder than I expected maybe b/c of the specifications of the problem. Help would be appreciated because I've turned this into a mess.

Input is a command line argument representing int between 0 and 255
Output: convert string to binary and output as array of numbers (0's and 1's)

I'll just throw out the basic algorithm since the program is on another pc.

-input comes in using argv/arg
-need to do error check for non numeric input. realized can't use isDigit
-use atoi to convert string to integer
-error check for value 0-255
-convert integer value to binary (several methods not sure which is most efficient?)
-store the binary values into array[8]

is something incorrect because it sure isn't working as simple as it sounds..

btw can't use <string.h>

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by cikara21
0

You can use isdigit( ) to validate the input - you just have to do it one character at a time. And know when to stop.

Your general algorithm seems sound. The last two steps are really one - as you do the conversion to binary, you will be filling an array. That's the only part of this problem that would be non-trivial.

Can't use <string.h>? Well, you should be using <cstring> anyway.

0

Sedikit informasi...
Semoga dapat membantu

#ifndef _MSC_VER
#include <string.h>
#else
#include <string>
#endif

//.....
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.