I have to convert an array of characters to a Binary value. Without using any C functions the only way that I know to check if something is an integer or letter is to use the ASCII chart. I followed the numbers in my functions but somehow it is not working out at all. The program executes and falls into every if statement even when it shouldnt.
thanks in advanceCode:int convert( const char Val[], int Base , int * InValue ) { int i; int count = 0; bool negFlag = 0; for( i = 0 ;; i++ ) { if ( Val[i] == '\0' ) { break; } printf ( "%i\n" , Val[i] ); if (Val[i]<=90 || Val[i]>=65); { printf ( "%i\n" , count ); count++; } } i = 0; int Base10Value = 0; int Base10Count = count; printf ( "%i\n" , count ); for( count ; count >= 0 ; ) { if ((65<=Val[i]<=90)or(97<=Val[i]<=122)); { int BaseToPower = 1 ; for ( Base10Count ; ( Base10Count - 1 ) > 0 ; Base10Count-- ) { BaseToPower *= Base; } if ( 65 <= Val[i] <= 90 ) { Base10Value += ( ((Val[i] - 'A')+10) * BaseToPower); } if (Val[i]<= 97 ) { Base10Value += ( ((Val[i] - 'a')+10) * BaseToPower); } count--; } if ( ( 48 <= Val[i] <= 57 )); { int BaseToPower = 1 ; for ( Base10Count ; ( Base10Count - 1 ) > 0 ; Base10Count-- ) { BaseToPower *= Base; } Base10Value += ( (Val[i] - '0') * BaseToPower); count--; } i++; }




Reply With Quote