2013-03-18 54 views
-1

我正在处理复制链表。解决了.h & .c文件。如何将主链接与.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; 
    } 

//。主要

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); 

//如何获得该功能的工作?这个功能到底是什么?它只能是这个功能。

+0

欢迎来到Stack Overflow。请阅读[常见问题]。在收到答案后(并通过删除大部分代码,破坏了自己的问题),不应该破坏问题。 – 2013-03-19 04:23:28

回答

1

在你的主,你需要

#include "YOUR.H" 

哪里YOUR.H是你展示在你的岗位的顶部.h文件的名称。

这将给YOUR.MAIN.C一个“承诺”,当您编译/链接给定的数据类型和功能将出现。它提供了足够的数据,以准备主要与YOUR.c链接。

当您编译时,确保将所有三个文件传递给编译器。它应该工作。你尝试过的更多细节将有助于得到更具体的答案。

2

如果您的.h和.c文件是test.ctest.h例如名称,把这个在你的main.cpp顶部

#include "test.h" 

然后你可以使用你的定义的所有功能头文件