问题描述
- 提领指向不完全类型的指针
-
#include
#include
#include
#include#define ID_MAX 10
#define NAME_MAX 20
#define MOBILE_MAX 15
#define ADDRESS_MAX 100
#define COMP_TEL_MAX 15
#define MAX 100
#define FAILURE 0
#define SUCCESS 1struct perison
{
char id[ID_MAX];
char name[NAME_MAX];
char mobileNum[MOBILE_MAX];
char address[ADDRESS_MAX];
char companyTel[COMP_TEL_MAX];
struct perison *prior;
struct perison *next;
};enum option{INSERT,DELETE,DISPLAY,SEARCH,exit 1};
typedef struct perison Linklist;
typedef struct Linklist *Link;void operation_Menu()
{
printf(" |---------------------------|
");
printf(" |--------电子通讯录---------|
");
printf(" |---------------------------|
");
printf(" |(A)添加好友信息 |
");
printf(" |---------------------------|
");
printf(" |(B)列表好友信息 |
");
printf(" |---------------------------|
");
printf(" |(C)搜索好友 |
");
printf(" |---------------------------|
");
printf(" |(D)删除好友 |
");
printf(" |---------------------------|
");
printf(" |(E)退出通讯录 |
");
printf(" |---------------------------|
");
}int create_linklist(Link *head,char id[])
{
*head = (Link)malloc(sizeof(Linklist));if(head == NULL) { printf("MALLOC ERROR!"); exit 1; } else { strcpy((*head)->id,id); strcpy((*head)->name,""); strcpy((*head)->mobileNum,""); strcpy((*head)->address,""); strcpy((*head)->companyTel,""); } (*head)->prior = *head; (*head)->next = *head;
}
int get_option(char *opt)
{
if(strcmp(opt,"INSERT") == 0)
{
return INSERT;
}if(strcmp(opt,"DISPLY") == 0); { return DISPLAY; } if(strcmp(opt,"SEARCH") == 0); { return SEARCH; } if(strcmp(opt,"DELETE") == 0); { return DELETE; } if(strcmp(opt,"EXIT") == 0) { return exit 1; }
}
int insert_linklist(Link *head, Link *newnode)
{
if(*head == NULL || *newnode == NULL)
{
printf("创建人员节点内存失败!
");
return 0;
}Link temp = *head; while(strcmp(temp->next->id,"") != 0) { temp = temp->next; } (*newnode)->next = *head; (*head)->prior = *newnode; temp->next = *newnode; (*newnode)->prior = temp; return 1;
}
void search_linklist(Link *head)
{
char namei[NAME_MAX];Link temp = *head; printf("请输入你要查询的姓名: "); scanf("%s",namei); while(strcmp(temp->name,namei) != 0) { temp = temp->next; if(strcmp(temp->name,namei) == 0) { display_node(&temp); } else { printf("没查找到此好友!"); break; } } break;
}
void delete_node(Link *head, char *namei)
{
Link temp = *head;while(strcpy(temp->next->name,namei) != 0) { temp = temp->next; } Link ptr = temp->next; temp->next = ptr->next; ptr->next->prior = temp; free(ptr); ptr = NULL;
}
void display_linklist(Link *head)
{
Link temp = *head;
temp = temp->next;printf("_________________________________________________________________________ "); printf("| ID | NAME | MOBILENUM | ADDRESS | COMPANYTEL | "); printf("|-----------------------------------------------------------------------| "); while(strcmp(temp->id,"") != 0) { printf("%-6d|%-14d|%-13d|%-20d|%-14d ",temp->id,temp->name,temp->mobileNum,temp->address,temp->companyTel); printf("_________________________________________________________________________ "); temp = temp->next; printf(" "); } printf(" ");
}
void display_node(Link *node)
{
printf("_________________________________________________________________________
");
printf("| ID | NAME | MOBILENUM | ADDRESS | COMPANYTEL |
");
printf("|-----------------------------------------------------------------------|
");
printf("%-6d|%-14d|%-13d|%-20d|%-14d
",(*node)->id,(*node)->name,(*node)->mobileNum,(*node)->address,(*node)->companyTel);
}int my_digit(char *str)
{
int flag = 1;while(*str != '') { str++; if(*str >= '0' || *str <= '9') { flag = 1; } else { flag = 0; } if(flag == 1) { return SUCCESS; } else { return FAILURE; } }
}
int main()
{
int i;
int opt;
int result;
char option[MAX];
char idi[ID_MAX];
char namei[NAME_MAX];
char mobileNumi[MOBILE_MAX];
char addressi[ADDRESS_MAX];
char companyTeli[COMP_TEL_MAX];Link head; Link newnode; operation_Menu(); create_linklist(&head); #if 1 while(1) { printf("请输入操作指令: "); scanf("%s",option); opt = get_option(option); switch(opt) { case INSERT: { while(1) { int resault; newnode = (Link)malloc(sizeof(Linklist)); printf(" ID:"); fflush(stdin); scanf("%s",idi); if(my_digit(idi) == FAILURE) { printf("请输入数字类型字符"); } strcpy(newnode->id,idi); printf(" NAME:"); fflush(stdin); scnaf("%s",namei); strcpy(newnode->name,namei); printf(" MOBILENNUM:"); fflush(stdin); scnaf("%s",mobileNumi); strcpy(newnode->mobileNum,mobileNumi); printf(" ADDRESS:"); fflush(stdin); scnaf("%s",addressi); strcpy(newnode->address,addressi); printf(" COMPANYTEL:"); fflush(stdin); scnaf("%s",companyTeli); strcpy(newnode->companyTel,companyTeli); result = insert_linklist(&head, &newnode); if(result == 0) { printf("添加好友失败!"); exit 0; } else { printf("添加好友成功!"); } fflush(stdin); break; }break; } case DISPLAY: { display_linklist(&head); break; } case DELETE: { delete_node(&head, namei); } case SEARCH: { search_linklist(&head); break; } default: { printf("请输入正确的指令: "); break; } } } #endif return 0;
}
解决方案
解决方案二:
今天编译C程序,出现错误:提领指向不完全类型的指针(Error: dereferencing pointer to incomplete type pointer)的错误。
之前没有遇到过,问了问Google,回答如下:
包含声明结构体定义的头文件。
这个错误多出现在访问结构或者联合体的成员。
由于结构体定义在了C文件里,为了解决这个错误,只好把函数写到C文件里。
错误的原因声明......
答案就在这里:错误:提领指向不完全类型的指针
解决方案三:
看到一长串代码并不开心~我觉得你自己先把错误定个位,把出错函数放上来大家一起商量,效率多高呢!
再说include了哪些头文件也并不能看到~。。。
你先把代码好好复制起~我就想看看除了stdio和stdlib你还用了什么库函数~
解决方案四:
错误真是挺多。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ID_MAX 10
#define NAME_MAX 20
#define MOBILE_MAX 15
#define ADDRESS_MAX 100
#define COMP_TEL_MAX 15
#define MAX 100
#define FAILURE 0
#define SUCCESS 1
struct perison
{
char id[ID_MAX];
char name[NAME_MAX];
char mobileNum[MOBILE_MAX];
char address[ADDRESS_MAX];
char companyTel[COMP_TEL_MAX];
struct perison *prior;
struct perison *next;
};
enum option{INSERT,DELETE,DISPLAY,SEARCH,exit1};
typedef struct perison Linklist;
typedef struct perison* Link;
void display_node(Link *node); //加一个声明
void operation_Menu()
{
printf(" |---------------------------|
");
printf(" |--------电子通讯录---------|
");
printf(" |---------------------------|
");
printf(" |(A)添加好友信息 |
");
printf(" |---------------------------|
");
printf(" |(B)列表好友信息 |
");
printf(" |---------------------------|
");
printf(" |(C)搜索好友 |
");
printf(" |---------------------------|
");
printf(" |(D)删除好友 |
");
printf(" |---------------------------|
");
printf(" |(E)退出通讯录 |
");
printf(" |---------------------------|
");
}
int create_linklist(Link *head,char id[])
{
*head = (Link)malloc(sizeof(Linklist));
if(head == NULL)
{
printf("MALLOC ERROR!");
exit(1); //加一个括号
}
else
{
strcpy((*head)->id,id);
strcpy((*head)->name,"");
strcpy((*head)->mobileNum,"");
strcpy((*head)->address,"");
strcpy((*head)->companyTel,"");
}
(*head)->prior = *head;
(*head)->next = *head;
return 0;
}
int get_option(char *opt)
{
if(strcmp(opt,"INSERT") == 0)
{
return INSERT;
}
if(strcmp(opt,"DISPLAY") == 0) //去掉一个分号
{
return DISPLAY;
}
if(strcmp(opt,"SEARCH") == 0) //去掉一个分号
{
return SEARCH;
}
if(strcmp(opt,"DELETE") == 0) //去掉一个分号
{
return DELETE;
}
if(strcmp(opt,"EXIT") == 0)
{
return exit1; //修改
}
return -1;
}
int insert_linklist(Link *head, Link *newnode)
{
if(*head == NULL || *newnode == NULL)
{
printf("创建人员节点内存失败!
");
return 0;
}
Link temp = *head;
while(strcmp(temp->next->id,"") != 0)
{
temp = temp->next;
}
(*newnode)->next = *head;
(*head)->prior = *newnode;
temp->next = *newnode;
(*newnode)->prior = temp;
return 1;
}
void search_linklist(Link *head)
{
char namei[NAME_MAX];
Link temp = *head;
printf("请输入你要查询的姓名:
");
scanf("%s",namei);
temp = temp->next;
while(strcmp(temp->id,"") != 0)
{
if(strcmp(temp->name,namei) == 0)
{
display_node(&temp);
return;
}
temp = temp->next;
}
printf("没查找到此好友!");
}
void delete_node(Link *head, char *namei)
{
Link temp = *head;
while(strcmp(temp->next->name,namei) != 0)
{
temp = temp->next;
}
Link ptr = temp->next;
temp->next = ptr->next;
ptr->next->prior = temp;
free(ptr);
ptr = NULL;
}
void display_linklist(Link *head)
{
Link temp = *head;
temp = temp->next;
printf("_________________________________________________________________________
");
printf("| ID | NAME | MOBILENUM | ADDRESS | COMPANYTEL |
");
printf("|-----------------------------------------------------------------------|
");
while(strcmp(temp->id,"") != 0)
{
printf("%-6s|%-14s|%-13s|%-20s|%-14s
",temp->id,temp->name,temp->mobileNum,temp->address,temp->companyTel);
printf("_________________________________________________________________________
");
temp = temp->next;
printf("
");
}
printf("
");
}
void display_node(Link *node)
{
printf("_________________________________________________________________________
");
printf("| ID | NAME | MOBILENUM | ADDRESS | COMPANYTEL |
");
printf("|-----------------------------------------------------------------------|
");
printf("%-6s|%-14s|%-13s|%-20s|%-14s
",(*node)->id,(*node)->name,(*node)->mobileNum,(*node)->address,(*node)->companyTel);
}
int my_digit(char *str)
{
int flag = 1;
while(*str != '')
{
if(*str >= '0' || *str <= '9')
{
flag = 1;
}
else
{
flag = 0;
}
str++;
if(flag == 1)
{
return SUCCESS;
}
else
{
return FAILURE;
}
}
return SUCCESS;
}
int main()
{
int opt;
int result;
char option[MAX];
char idi[ID_MAX]="";
char namei[NAME_MAX];
char mobileNumi[MOBILE_MAX];
char addressi[ADDRESS_MAX];
char companyTeli[COMP_TEL_MAX];
Link head;
Link newnode;
operation_Menu();
create_linklist(&head, idi); //这里修改
while(1)
{
printf("请输入操作指令:
");
scanf("%s",option);
opt = get_option(option);
switch(opt)
{
case INSERT:
{
while(1)
{
newnode = (Link)malloc(sizeof(Linklist));
printf("
ID:");
fflush(stdin);
scanf("%s",idi);
if(my_digit(idi) == FAILURE)
{
printf("请输入数字类型字符");
}
strcpy(newnode->id,idi);
printf("
NAME:");
fflush(stdin);
scanf("%s",namei);
strcpy(newnode->name,namei);
printf("
MOBILENNUM:");
fflush(stdin);
scanf("%s",mobileNumi);
strcpy(newnode->mobileNum,mobileNumi);
printf("
ADDRESS:");
fflush(stdin);
scanf("%s",addressi);
strcpy(newnode->address,addressi);
printf("
COMPANYTEL:");
fflush(stdin);
scanf("%s",companyTeli); //拼写错误,scanf
strcpy(newnode->companyTel,companyTeli);
result = insert_linklist(&head, &newnode);
if(result == 0)
{
printf("添加好友失败!");
exit(0); //加一个括号
}
else
{
printf("添加好友成功!");
}
fflush(stdin);
break;
}break;
}
case DISPLAY:
{
display_linklist(&head);
break;
}
case DELETE:
{
printf("请输入要删除人的姓名:");
scanf("%s",namei);
delete_node(&head, namei);
break;
}
case SEARCH:
{
search_linklist(&head);
break;
}
case exit1:
return 0;
default:
{
printf("请输入正确的指令:
");
break;
}
}
}
return 0;
}