小编use*_*842的帖子

不使用printf()时出现malloc错误

#include <stdio.h>
#include <stdlib.h>
typedef struct lis
{
    int num;
    struct lis * next;
} list;
void  fun(list ** h, int nu) {
    *h = malloc(sizeof(list)*nu);
    list *p = *h;
    int i=1;
    list * nextx;
    while(i<=nu) {
        nextx = p + 1;
        p->num = i;
        p->next = nextx;
        //printf("%d\n", nextx);
        p += 1;
        i++;
    }
    p->next = NULL;
}


int main(int argc, char const *argv[])
{
    list * first = NULL;
    fun(&first,10);
    free(first);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在学习c中的列表

无论何时运行此代码,都会产生malloc错误

如果我注释掉printf("%d\n", …

c malloc

-1
推荐指数
1
解决办法
168
查看次数

标签 统计

c ×1

malloc ×1