Okay, so I have this piece of code here to input a string from user and convert it to a string half of the size. It works for all inputs except for ones with Zeroes in the middle. For example:
INPUT: 1234
OUTPUT: 0, 6, 1, 7
INPUT: 1230
OUTPUT: 0, 6
INPUT: 12
OUTPUT: 0, 6
INPUT: 10
OUTPUT: _____ (NOTHING), it doesn't even print the text in the printf statement
Why would a case with 0's in it be any different for what I am doing here?
Code:
#include <stdio.h>
#include <string.h>
int main(){
char array[256];
fgets(array,255,stdin);
int f;
for(f=0;f<strlen(array)-1;f++){
array[f] -= 48;
}
int i;
int last_cell = strlen(array)-2;
i = last_cell;
for(i=last_cell ; i>=0; i--){
int flag = 0;
if( i != 0 && (array[i - 1] % 2) == 1)
flag = 1;
array[i] /= 2;
if(flag == 1){
array[i] += 5;
}
}
int j;
for(j=0;j<=last_cell;j++){
printf("array[%d] == %d,",j,array[j]);
}
}