帮我看下这个短小的.h头文件的问题

/*  file1: contactbook.h  */
#ifndef CONTACTBOOK_H
#define CONTACTBOOK_H

/******************************************************************
* Data Structure: Contact(Node)  Contactbook(List)                *
******************************************************************/
struct contact;
typedef struct contact Contact;
typedef Contact *Contactbook;
typedef Contact *Position;

/******************************************************************
* ID: Every contact have a unique ID number(genereated by system) *
*      and it is linked to a storage location.                    *
******************************************************************/
typedef unsigned int ID;

/* fuzzy_search_results: A struct to save fuzzy search results   */
const int MAX_CONTACTS = 1024;
struct fuzzy_search_results;
typedef struct fuzzy_search_results Contactbook_Findings;
Contactbook_Findings finding_results[MAX_CONTACTS];

/******************************************************************
* make_empty_contactbook: Make an empty contactbook.              *
******************************************************************/
void make_empty_contactbook( Contactbook new_contactbook );

/******************************************************************
* add_contact: Add a contact to a current contactbook.            *
******************************************************************/
void add_contact( Contact new_contact, Contactbook cur_contactbook );

/* sort_contact: Sort the whole contactbook by alpha order.      */
void sort_contact( Contactbook cur_contactbook );

/* sort_contactbook_findings: Sort the findings by alpha order.  */
void sort_contactbook_findings( Contactbook_Findings cur_contactbook );

/******************************************************************
* fuzzy_search_contact: Through search information, check all the *
*                       possible results, and save them into a    *
*                       Findings(struct).                         *
******************************************************************/
void fuzzy_search_contact( char** search_string, Contactbook cur_contactbook, Contactbook_Findings* finding_results ); 

/******************************************************************
* delete_contact: Delete contact from a current contactbook.      *
*                 Return ID for Simcard deleting.                 *
******************************************************************/
ID delete_contact( Contactbook cur_contactbook ); 

/* print_contacts: Print all the contacts in contactbook.        */
void print_contacts( Contactbook cur_contactbook );

#endif

/*    file2: contactbook.c   */
#include <string.h>
#include "contactbook.h"

struct contact{
    ID id_number;
    char name[64];
    char sex[16];
    char tel[64];
    char email_address[128];
    char address[256];
};

struct fuzzy_search_results{
    ID id_number;
    char name[64];
    Position this_contact;
};

/*  functions ...     */

/*    compile error report:   */

2 C:\Users\JY\Desktop\workspace\Virtual ContactBook\contactbook.c In file included from C:\Users\JY\Desktop\workspace\Virtual ContactBook\contactbook.c 
22 C:\Users\JY\Desktop\workspace\Virtual ContactBook\contactbook.h variable-size type declared outside of any function 
32 C:\Users\JY\Desktop\workspace\Virtual ContactBook\contactbook.h [Warning] parameter has incomplete type 
38 C:\Users\JY\Desktop\workspace\Virtual ContactBook\contactbook.h [Warning] parameter has incomplete type 

/*  thank you for helping me to improve    */

阅读 3.3k
1 个回答
variable-size type declared outside of any function 

类型的长度是变长的。

const int MAX_CONTACTS = 1024;
Contactbook_Findings finding_results[MAX_CONTACTS];

这样不行的。变长数组只允许在函数内定义。关于那个const,参见 http://stackoverflow.com/a/5204352/296473

struct contact;
typedef struct contact Contact;
typedef Contact *Contactbook;
typedef Contact *Position;

void add_contact( Contact new_contact, Contactbook cur_contactbook );

struct contact的定义不完整。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进