Hello, I have problems with this code that must convert an integer to binary and keep the zeros and ones in a pointer of type char. However after the execution the pointer only returns a 1 and not all the values of the string
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int * permutaInt;
char * permuta(char * str, int x, int base) {
int division = x;
int posicion = 0;
int *copia;
while (division != 0) {
str[posicion] = 48 + (division % base);
division = division / base;
posicion++;
}
posicion = 0;
while (str[posicion] != '#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int * permutaInt;
char * permuta(char * str, int x, int base) {
int division = x;
int posicion = 0;
int *copia;
while (division != 0) {
str[posicion] = 48 + (division % base);
division = division / base;
posicion++;
}
posicion = 0;
while (str[posicion] != '%pre%') {
posicion++;
}
copia = (char*) malloc(posicion * sizeof (char));
posicion = posicion - 1;
int contador = 0;
while (posicion != -1) {
copia[contador] = str[posicion];
posicion--;
contador++;
}
copia[contador++]='%pre%';
contador=0;
return copia;
}
int main() {
char *str;
char *recibido;
str =(char*)malloc(100*sizeof(char));
int x = 0;
int base = 2;
int contador=0;
printf("Ingresa tu numero \n");
scanf("%d", & x);
recibido=permuta(str, x, base);
printf("%s",recibido);
return (EXIT_SUCCESS);
}
') {
posicion++;
}
copia = (char*) malloc(posicion * sizeof (char));
posicion = posicion - 1;
int contador = 0;
while (posicion != -1) {
copia[contador] = str[posicion];
posicion--;
contador++;
}
copia[contador++]='%pre%';
contador=0;
return copia;
}
int main() {
char *str;
char *recibido;
str =(char*)malloc(100*sizeof(char));
int x = 0;
int base = 2;
int contador=0;
printf("Ingresa tu numero \n");
scanf("%d", & x);
recibido=permuta(str, x, base);
printf("%s",recibido);
return (EXIT_SUCCESS);
}