1
I have a whole number n
I wish to break (separate your digits) and store in a vector, but my code does not work... what I am missing?
#define TRUE 1
#define FALSE 0
#define DIM1 3
#define DIM2 3
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<math.h>
int* retorna_quebrado(int a,int &p){
int* vet;
int i=0;
while(a>0){
vet = (int*) malloc(sizeof(int));
vet[i]=a%10;
a=a/10;
i++;
}
p=i;
return vet;
}
int main(){
int n;
int p;
int* vet = retorna_quebrado(n,p);
scanf("%d",&n);
for(int i=0 ; i<p;i++)
printf(" \n %d",vet[i]);
return 0;
}
What is the compiler return message? Or what error is happening?
– Mateus
added an input and an output
– Sergio Souza Novak