简体   繁体   中英

Cannot use malloc.h in xcode?

#if 0

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <malloc.h>

#define ColSize 2

void inputData(double*, int*, int i, int CSize);

void printdata(double*, int*, int i, int CSize);

int main(void)
{
    double *RATE;
    int *MIN_BALANCE;
    int i, CSize;
   
    RATE = (double*)malloc(sizeof(double)*ColSize);
    MIN_BALANCE = (int*)malloc(sizeof(int)*ColSize);
    
    i = 0;
    CSize = ColSize;
    inputData(RATE, MIN_BALANCE, i, CSize);
    printdata(RATE, MIN_BALANCE, i, CSize);
    
    free(RATE);
    free(MIN_BALANCE);
    
    return 0;
}
void inputData(double *RATE, int *MIN_BALANCE, int i, int CSize)
{
    for (i = 0; i < CSize; i++)
    {
        scanf("%lf", (RATE+i));
        
        scanf("%d", (MIN_BALANCE+i));
    }
    return;
}
void printdata(double *RATE, int *MIN_BALANCE, int i, int CSize)
{
    for (i = 0; i < CSize; i++)
    {
        printf("rate: %f\n", *(RATE + i));
        printf("balance: %d\n", *(MIN_BALANCE + i));
    }
    return;
}
#endif

I ran the above code but I got an error message which is 'malloc.h'file not found. I am using xcode of Mac. How do I fix the error?

malloc.h is non-standard. Use stdlib.h per the C standard .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM