gpt4 book ai didi

c - 如何将 main 与 .h 链接。 .c 文件

转载 作者:行者123 更新时间:2023-11-30 18:42:40 28 4
gpt4 key购买 nike

我正在研究双链表。制定了 .h 和 .c 文件。

//.h -file

typedef struct Data_t{
int d_sz;
void * data;
}data_t, * data_ptr_t;

typedef struct List_t{
int index;
struct List_t * next;
struct List_t * prev;
data_t * d;
}list_t, * list_ptr_t;

//.c 文件

/**
* Inserts a new element containing 'data' in 'list' at position 'index' and returns a pointer to the new list.
* If 'index' is 0 or negative, the element is inserted at the start of 'list'.
* If 'index' is bigger than the number of elements in 'list', the element is inserted at the end of 'list'.
*/
list_ptr_t list_insert_at_index( list_ptr_t list, data_ptr_t data, int index){

// add data to newlist
return newlist;
}

//.main

int i;
int value;


data_ptr_t h;
list_ptr_t l;
printf("Enter a value:");
scanf("%d",&value);

l = list_insert_at_index( ? , ?, 0);

//如何让函数工作?这个功能到底要做什么?它必须只是这个功能。

最佳答案

例如,如果您的 .h 和 .c 文件的名称是 test.ctest.h,请将其放在 main.cpp 的顶部

#include "test.h"

然后就可以使用你在头文件中定义的所有函数了

关于c - 如何将 main 与 .h 链接。 .c 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15486038/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com