I think some major clarificarion is needed.
I was wondering if anyone can help me in terms of using atoi to get my my results to add the 1's of my binary output and then join them together... eg. 110101 and 100101 is 4 and 3 = 43.
Do you mean you want to convert series of 1's and 0's typed in by the user into it'soctal (base 8) representation? That's what this example shows. There is nothing decimal (base 10) about it. In decimal, this value is 37, not 43.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Some basic parts:
#include <stdio.h>
int count_ones(const char *text)
{
int ones = 0;
for ( ; *text; ++text )
{
if ( *text == '1' )
{
++ones;
}
}
return ones;
}
int main(void)
{
const char *text[] =
{
"1101110", "1001101", "1011011",
};
int total = 0;
size_t i;
for ( i = 0; i < sizeof text / sizeof *text; ++i )
{
total *= 10;
total += count_ones(text[i]);
}
printf("total = %d\n", total);
return 0;
}
/* my output
total = 545
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314