How does it work when you get a variable and make char-48
to transform into an integer, for example in this code I made, I used a date for example "22/05/1994" stored in a char vector and turned it into day, month and year all in integer value. The fact happens in line 5 in the expression num[j]=data[i]-48
. What happens in this operation to happen the conversion?
void transformarDataEmInt(char *data, int *dia, int *mes, int *ano){
int i,j=0;
int num[8];
for (i=0; i<10; i++) {
num[j]=data[i]-48;
if (i==2||i==5){
continue;
}
j++;
}
*dia = num[0]*10 + num[1];
*mes = num[2]*10 + num[3];
*ano = num[4]*1000 + num[5]*100 + num[6]*10 + num[7];
}