Necesito saber porque se imprimen los números de el arreglo con ceros incluidos en la funcion getbval.
#include <stdio.h>
#include <string.h>
int getbval(char num[], char base[], unsigned int **valorptr);
int validar(int partes[], char base[], char num[]);
void remplazar(char num[], int **partes);
main(){
char entrada[255];
char num[50];
char base[2];
char delim[] = "#";
int i = 0;
unsigned int * valor;
fflush(stdin);
printf("inserte numero:");
scanf("%s", &entrada);
if (strstr(entrada, "#") == NULL) { //si no se especifica base se asume base 10
strcat(entrada, "#10");
}
char * token = strtok(entrada, delim);
while (token != NULL){ //strtok separa la entrada en lo que viene antes y despues del #. se asigna respectivamente
if (i == 0){
strcpy(num, token);
i++;
} else if (i == 1) {
if (token == NULL) {
strcpy (base, "10");
} else {
strcpy(base, token);
}
}
token = strtok(NULL, "#");
}
if (getbval(num, base, &valor) == 1){ //revision de
printf("La entrada es: %s, la base es: %s, y el valor es: %i", num, base, valor);//temporal para revisar los valores
} else {
printf("error");
}
}
int getbval(char num[], char base[], unsigned int **valorptr){
int valor, i;
int partes[255];
remplazar(num, &partes);
printf("partes: \n");
for (i=NULL; i<strlen(num); i++){ //temporal
printf("%i\n", partes[i]); //temporal
} //temporal
if (validar(partes, base, num) == 1){
*valorptr = 125;
return(1); //temporal
} else {
return(0);
}
}
void remplazar(char num[], int **partes){
int i;
for (i=0; i < strlen(num); i++){
if (num[i] == '1'){
partes[i] = 1;
} else if (num[i] == '2'){
partes[i] = 2;
} else if (num[i] == '3'){
partes[i] = 3;
} else if (num[i] == '4'){
partes[i] = 4;
} else if (num[i] == '5'){
partes[i] = 5;
} else if (num[i] == '6'){
partes[i] = 6;
} else if (num[i] == '7'){
partes[i] = 7;
} else if (num[i] == '8'){
partes[i] = 8;
} else if (num[i] == '9'){
partes[i] = 9;
} else if (num[i] == 'a'){
partes[i] = 10;
} else if (num[i] == 'b'){
partes[i] = 11;
} else if (num[i] == 'c'){
partes[i] = 12;
} else if (num[i] == 'd'){
partes[i] = 13;
} else if (num[i] == 'e'){
partes[i] = 14;
} else if (num[i] == 'f'){
partes[i] = 15;
} else if (num[i] == 'g'){
partes[i] = 16;
} else if (num[i] == 'h'){
partes[i] = 17;
} else if (num[i] == 'i'){
partes[i] = 18;
} else if (num[i] == 'j'){
partes[i] = 19;
} else if (num[i] == 'k'){
partes[i] = 20;
} else if (num[i] == 'l'){
partes[i] = 21;
} else if (num[i] == 'm'){
partes[i] = 22;
} else if (num[i] == 'n'){
partes[i] = 23;
} else if (num[i] == 'o'){
partes[i] = 24;
} else if (num[i] == 'p'){
partes[i] = 25;
} else if (num[i] == 'q'){
partes[i] = 26;
} else if (num[i] == 'r'){
partes[i] = 27;
} else if (num[i] == 's'){
partes[i] = 28;
} else if (num[i] == 't'){
partes[i] = 29;
} else if (num[i] == 'u'){
partes[i] = 30;
} else if (num[i] == 'v'){
partes[i] = 31;
} else if (num[i] == 'w'){
partes[i] = 32;
} else if (num[i] == 'x'){
partes[i] = 33;
} else if (num[i] == 'y'){
partes[i] = 34;
} else if (num[i] == 'z'){
partes[i] = 35;
}
}
}
int validar(int partes[], char base[], char num[]){
int i, flag=1;
for (i=0; i < strlen(num); i++){
if (partes[i] > (int) base){
flag = 0;
}
}
if (flag == 1){
return (1);
} else {
return (0);
}
}