How could that be it though. I probably should have mentioned this, but I initialized the array to 50 cells. I'm merely trying to access the 4th or 5th or 6th one.
Just to be sure, I left the code in tact, and deleted the commented portion that I contend is causing some bizarre seg fault. Here is the relevant code. I know I'm probably missing some grave mistake here but if anyone could explain why this is happening I will be very much in your debt.
Code:
#include <stdio.h>
#include <string.h>
int multiplyByTwo(char*, int);
int divideByTwo(char*, int);
int main(){
char array[256];
char fraction[50];
fgets(array,255,stdin);
int f;
int last_cell = strlen(array)-2;
int j;
for(j=0;j<last_cell;j++){
if(array[j] == '.')break;
}
int decimal_location = j;
int fraction_length = last_cell - decimal_location;
for(f=0;f<strlen(array)-1;f++){
array[f] -= 48;
}
int k=0;
for(j++;j<=last_cell;j++,k++){
fraction[k] = array[j];
printf("f[%d] = %d ",k,fraction[k]);
}
fraction[k+1] == 0;
fraction[k+2] == 0;
printf("fractionlength = %d\n",fraction_length - 1);
multiplyByTwo(fraction, fraction_length - 1);
printf("\ndecimal_location = %d\n",decimal_location);
printf("last_cell == %d\n",last_cell);
int num = 0;
int binary_array[50];
int s;
printf("Integral divided by two == ");
divideByTwo(array, decimal_location - 1);
}
int multiplyByTwo(char *fraction, int fraction_length)
{
printf("last_Cell = %d",fraction_length);
int j;
for(j=fraction_length;j>=0;j--){
fraction[j+1] = fraction[j];
}
fraction[0] = 0; printf("\n\n");
for(j=0;j<fraction_length+2;j++)
printf("%d ",fraction[j]);
}