Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: initialization makes pointer from integer without a cast in C

Tags:

c

I am getting the warning: initialization makes pointer from integer without a cast in C. What is a cast? What should I do?

void UpdateElement(Console* console)
{
    DynamicVector* CostList=getAllCosts(console->ctrl);
    int i,n;
    printf("Give the position of the element you want to delete:");
    scanf("%d",&n);
    for(i=n-1;i<getLen(CostList);i++)
    {
        Cost* c=(Cost*)getElementAtPosition(CostList,i);
        Cost* c2=AddCost(console); **//here I get the warning**
        update_an_element(console->ctrl,c,c2,i);
    }
}

Console* initConsole(Controller* ctrl)
{
    Console* console=(Console*)malloc(sizeof(Console));
    console->ctrl=ctrl;
    return console;
}

int createCost(Controller* ctrl, char* day, char* type, int sum)
{
    Cost* c=initCost(day,type,sum);
    save(ctrl->repo,c);
    return c; **//now here I get the warning**

}
like image 288
Cucerzan Rares Avatar asked Jun 03 '26 10:06

Cucerzan Rares


1 Answers

c is of type Cost* and the function createCost returns int. both are not compatible that's why the compiler complains about a missing cast, but you don't want to cast in this case.

Change the return type of that function to Cost*

like image 165
A4L Avatar answered Jun 06 '26 01:06

A4L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!