It looks like you're mixing solutions, and you added too much fluffy code without getting a solid solution first.
>char binaryinput[8];
If you're going to print binaryinput as a string later, you need to leave room for a null character at the end.
>printf("\tPlease enter an 8-bit binary bits:");
If you don't print a newline, be sure to call fflush so that the output is guaranteed to be shown before blocking for input. You're not likely to have a problem on Windows systems, but this is a portability concern.
>for(i=7; i<8; i--)
You really only need to loop from 0 to 8. No tricks needed, and this loop is severely broken.
>if(binaryinput[0] == '1')
Obviously you'll need to compare against binaryinput[i] rather than binaryinput[0] , otherwise the loop won't work as intended.
result = binaryinput[i] * pow(2,0);
is pointless as written, but I suspect what you wanted was to add the result of pow to result :
result += (int)pow ( 2, 7 - i ); The cast to int will silence a warning about double truncation, and 7-i gets you the right exponent from the loop index.>else if(binaryinput[0] == '0')
This comparison isn't necessary as work only needs to be done for set bits.
All of the problems are pretty simple, and it looks like you have a fairly good idea of how the solution should work, so I'll give you my version of the code to compare and contrast:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define BASE 2
#define BITS 8
#define HIBIT 7
#define LOBIT 0
static const char *prompt_msg =
"Please enter an %d-bit binary number: ";
static const char *result_msg =
"%s binary has been converted to %d decimal\n";
int main ( void )
{
char binaryinput[BITS + 1] = {0};
int result = 0;
int i;
printf ( prompt_msg, BITS );
fflush ( stdout );
for ( i = LOBIT; i < BITS; i++ )
binaryinput[i] = (char)getchar();
for ( i = LOBIT; i < BITS; i++ ) {
if ( binaryinput[i] != '0' )
result += (int)pow ( BASE, HIBIT - i );
}
printf ( result_msg, binaryinput, result );
return 0;
}