Witam, próbuje zrobić mój pierwszy bardziej rozbudowany program w c i mam parę błedów, których nie moge rozwiązać.
Przy zwalnianiu pamięci: linia 66 warning: passing argument 1 of 'free' makes pointer from integer without cast
linia 358 expected 'void*' but argument is of type 'int'
I program na razie działa dla liczb maks. 4 cyforwych przy większej ilości cyfr tworzy coś w stylu petli nieskończonej.
Czy ktos ma pomysł jak zmienić funkcje howmanydigits żeby nie było potrzebne słowo static?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int howmanydigits(int n)
{
static int x=0;
do
{
n/=10;
x++;
}while(n>=1);
return x;
}
int main()
{
long a,b;
int adigits,bdigits,cdigits;
printf("Podaj po spacji liczby calkowite, ktore mam dodac: ");
scanf("%ld",&a);
scanf("%ld",&b);
adigits=howmanydigits(a);
bdigits=howmanydigits(b)-adigits;
if(adigits>bdigits) cdigits=adigits+1;
else cdigits=bdigits+1;
int *taba=malloc(adigits*sizeof(int));
int *tabb=malloc(bdigits*sizeof(int));
int *tabc=malloc(cdigits*sizeof(int));
int i;
int x=pow(10,adigits-1);
for(i=0;i<adigits;i++)
{
taba[i]=a/x;
a-=taba[i]*x;
x/=10;
}
x=pow(10,bdigits-1);
for(i=0;i<bdigits;i++)
{
tabb[i]=b/x;
b-=tabb[i]*x;
x/=10;
}
for(i=0;i<adigits;i++)
{
printf("%d. %d\n",i,taba[i]);
}
for(i=0;i<bdigits;i++)
{
printf("%d. %d\n",i,tabb[i]);
}
free(adigits);
free(bdigits);
free(cdigits);
return 0;
}
Z góry dzięki za pomoc :D