error:invalid preprocessing directive #include
无效的预处理 ,这是怎么回事头文件我确定没写错,#include<stdio.h>
#inlcude <stdlib.h>
#include "operation.h" (这是我自己写的)
这是学校作业通讯录系统,附上代码:[local]2[/local]
2016-09-07 16:04
2016-09-07 16:10
2016-09-07 16:22
2016-09-07 16:24
2016-09-07 16:47
2016-09-07 17:28
程序代码:#include <stdio.h>
#include "operation.h"
int main ()
{
for(;;)
{
switch(menu_select())
{
case 1:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 建 立 *\n");
printf("*****************************************\n");
head=CreateList();
break;
case 2:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 插 入 *\n");
printf("*****************************************\n");
printf("请输入 : 编号,姓名,性别,电话和地址 ") ;
printf("*****************************************\n");
p=(ListNode *)malloc(sizeof(ListNode));
scanf("%s%s%s%s%s",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
InsertNode(head,p);
break;
case 3:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 查 询 *\n");
printf("*****************************************\n");
p=ListFind(head);
if(p!=null)
{
printf("编号 姓名 性别 电话 地址\n");
printf("========================================\n");
printf("%s %s %s %s %s \n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
printf("========================================\n");
}
else
printf("没查找到要查询的通讯者");
break;
case 4:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 修 改 *\n");
printf("*****************************************\n");
ChangeNode(head);
break;
case 5:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 删 除 *\n");
printf("*****************************************\n");
DelNode(head);
break;
case 6:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 输 出 *\n");
printf("*****************************************\n");
printList(head);
break;
case 0:
printf(" 再 见!\n");
return;// int main() return 不能为空
}
}
}
程序代码:#include <stdio.h>
#include <stdlib.h>
typedef struct{
int num[5];
char name[9];
char sex[3];
char phone[13];
char addr[31];
}DataType;
typedef struct node{
DataType data;
struct node *next;
}ListNode,*LinkList;//typedef 不能一次做两个命名。现在你的写法只是声明了ListNode,LinkList是一个指针,要想命名必须另起一行写typedef
LinkList head;
ListNode *p;
extern int menu_select();
extern LinkList CreateList();
extern void InsertNode(LinkList head,ListNode *p);
extern ListNode *ListFind(LinkList head);
extern void DelNode(LinkList head);
extern void PrinfList(LinkList head);
extern ChangeNode(LinkList head);
/*
菜单选择函数
*/
int menu_select()
{
int sn;
printf(" 通讯录管理系统 \n");
printf("========================================\n");
printf(" 1.通讯录链表建立 \n");
printf(" 2.通讯录链表插入 \n");
printf(" 3.通讯录链表查询 \n");
printf(" 4.通讯录链表修改 \n");
printf(" 5.通讯录链表删除 \n");
printf(" 6.通讯录链表输出 \n");
printf("========================================\n");
printf(" 请 选 择 0-6 :");
for(;;)
{
scanf("%d",&sn);
if(sn<0||sn>6)
printf("\n\t输入错误,重选0-6");
else
break;
}
return sn;
}
/*
**尾插法建立链表
*/
LinkList CreateList() //这里编号可能出现学生重复某个编号所以直接用num++来编辑编号
{
LinkList head=(LinkNode *)malloc (sizeof(LinkNode));
ListNode *p,*rear;
rear=head;
int i=0; //i用来统计人数
printf("请输入需要记录通讯录的人数"); //这里使用一个for循环来登记通讯录信息
scanf("%d",&i); //这样会变得简洁 且每次循环少了一次判断 是否继续输入
for(int count=0;count<=i;count++)
{
p=(LinkNode *)malloc(sizeof(LidtNode));
printf("请按顺序输入姓名,性别,电话和地址\n");
scanf("%s%s%s%s",p->data.name,p->data.sex,p->data.phone,p->data.addr);
if(conut==0)//拼写错误
p->data.num=1;//num是数组,,这个赋值出错
else
p->data.num++;//同上
p=rear->next;
rear=p;
}
rear->next=null;//NULL 不是null 注意区分大小写
return head;
}
/**
***插入节点
**/
void InsertNode(LinkList head,ListNode *p)
{
LinkNode *p1,*p2;
p1=head;
p2=p1->next;
while (p2!=null&&p2->data.nump->data.num)//null是个未定义的东西
{
p1=p2;
p2=p2->next;
}
p1->next=p;
p->next=p2;
}
/*
**查询链表
*/
ListNode *ListFind(LinkList head)
{
LinkNode *p;
char num[5];
char name[9];
int xz;
printf("========================================\n");
printf(" 1.按编号查询 /n");
printf(" 2.按姓名查询 /n");
printf("========================================\n");
printf(" 请 选 择: ");
p=head->next;
scanf("%d",&xz);
if(xz==1)
{
printf("请输入要查找的编号:");
scanf("%s",num);
while(p&&p->data.num<num)
p=p->next;
if(p==null||p->data.num>num){
p=null;
printf("没有找到");
}
}
else
if(xz==2)
{
printf("请输入要查找的姓名:");
scanf("%s",name);
while(p&&strcmp(p->data.name,name)!=0)//缺少include 《string.h》
p=p->next;
}
return p;
}
/*
**删除节点
*/
void DelNode(LinkList)
{
char jx;
LinkNode *p,*q;
p=LinkFind(head);//ListFind? 你练函数名都搞混淆了
if(p==null) //...
{
printf("没有找到");
return;
}
printf("真的要删除节点吗?(y/n): ");
//getchar();
scanf("%c",&jx);
if(jx=='y'||jx=='Y')
{
q=head;
while(q!=null&&q->next!=p)
q=p->next;
q-next=p->next; //q-next什么鬼
free(p);
printf("通讯录已删除。");
}
}
/*
**输出函数
*/
void printList(LinkList head)
{
LinkNode *p;
p=head->next;
printf("编号 姓名 性别 电话 地址\n");
printf("========================================\n");
while(p!=null){
printf("%s %s %s %s %s \n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
printf("========================================\n");
p=p->next;
}
}
/*
**修改通讯录
*/
void ChangeNode(LinkList head)
{
LinkNode *p;
p=ListFind(head);
if(p!=null)
{
printf("编号 姓名 性别 电话 地址\n");
printf("========================================\n");
printf("%s %s %s %s %s \n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
printf("========================================\n");
Printf("输入该通讯录者的正确的联系电话,通讯地址:\n 中间用空格隔开");
scanf("%s$s",p->data.phone,p->data.addr);
}
else
printf("没查到要修改的通讯录!\n");
} 对于这类代码量不大的问题,还是不要上传附件了,直接贴代码,方便别人运行调试。还有你的问题还真的都是比较初级的,编译一下就可以定位修改了
2016-09-07 18:54
2016-09-07 19:17
程序代码:#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include "operation.h"
int main ()
{
ListNode *root=NULL;
while (1)
{
switch(menu_select())
{
case 1:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 建 立 *\n");
printf("*****************************************\n");
root = CreateList();
printf("\n *通讯录创建成功*\n\n");
printList(root);
break;
case 2:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 插 入 *\n");
printf("*****************************************\n");
printf("请输入 : 编号,姓名,性别,电话和地址 \n ") ;
printf("*****************************************\n");
p=(ListNode *)malloc(sizeof(ListNode));
if (p == NULL){ printf("error\n"); system("pause"); }
scanf("%d%s%s%s%s",&(p->data.num),p->data.name,p->data.sex,p->data.phone,p->data.addr);
InsertNode(root, p);
break;
case 3:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 查 询 *\n");
printf("*****************************************\n");
p=ListFind(root);
if(p!=NULL)
{
printf("编号 姓名 性别 电话 地址\n");
printf("========================================\n");
printf("%d %s %s %s %s \n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
printf("========================================\n");
}
else
printf("没查找到要查询的通讯者");
break;
case 4:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 修 改 *\n");
printf("*****************************************\n");
ChangeNode(root);
break;
case 5:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 删 除 *\n");
printf("*****************************************\n");
DelNode(root);
break;
case 6:
printf("*****************************************\n");
printf("* 通 讯 录 链 表 的 输 出 *\n");
printf("*****************************************\n");
printList(root);
break;
case 0:
printf(" 再 见!\n");
return;
}
}
} 复制operation.h
程序代码:#ifndef _STDIO_H
#define _STDIO_H
#endif
#ifndef _STDLIB_H
#define _STDLIB_H
#endif
#define see system("pause")
typedef struct{
int num;
char name[9];
char sex[3];
char phone[13];
char addr[31];
}DataType;
typedef struct node{
DataType data;
struct node *next;
}ListNode,*LinkList;
LinkList head;
ListNode *p;
extern int menu_select();
extern LinkList CreateList();
extern void InsertNode(LinkList head,ListNode *p);
extern ListNode *ListFind(LinkList head);
extern void DelNode(LinkList head);
extern void PrinfList(LinkList head);
extern void ChangeNode(LinkList head);
//extern ListNode *listsearch(LinkList root);
/*
菜单选择函数
*/
int menu_select()
{
int sn;
printf(" 通讯录管理系统 \n");
printf("========================================\n");
printf(" 1.通讯录链表建立 \n");
printf(" 2.通讯录链表插入 \n");
printf(" 3.通讯录链表查询 \n");
printf(" 4.通讯录链表修改 \n");
printf(" 5.通讯录链表删除 \n");
printf(" 6.通讯录链表输出 \n");
printf("========================================\n");
printf(" 请 选 择 0-6 :");
while (1)
{
scanf("%d",&sn);
if(sn<0||sn>6)
printf("\n\t输入错误,重选0-6");
else
break;
}
return sn;
}
/*
**尾插法建立链表
*/
LinkList CreateList() //这里编号可能出现学生重复某个编号所以直接用num++来编辑编号
{
LinkList head=(ListNode *)malloc(sizeof(ListNode));
ListNode *p,*rear;
rear=head;
int i=0; //i用来统计人数
int count;
printf("请输入需要记录通讯录的人数"); //这里使用一个for循环来登记通讯录信息
scanf("%d",&i); //这样会变得简洁 且每次循环少了一次判断 是否继续输入
for(count=0;count<i;count++)
{
p=(ListNode *)malloc(sizeof(ListNode));
if (p == NULL){ printf("error"); see; }
printf("请按顺序输入姓名,性别,电话和地址\n");
scanf("%s%s%s%s",p->data.name,p->data.sex,p->data.phone,p->data.addr);
p->data.num=count+1;
rear->next=p;
rear = p;
}
rear->next=NULL;
return head;
}
/**
***插入节点
**/
void InsertNode(LinkList head,ListNode *p)
{
ListNode *p1;
p1=head;
p1=p1->next;
while (p1!=NULL&& p1->data.num<p->data.num)
{
if (p1->next == NULL)
{ p1->next = p;
p->next = NULL;
break;
}
else p1 = p1->next;
}
p1->next=p;
p->next=p1->next->next;
printf("insert successful\n");
}
/*
**查询链表
*/
ListNode *ListFind(LinkList head)
{
ListNode *p;
int n;
char name[9];
int xz;
printf("========================================\n");
printf(" 1.按编号查询 \n");
printf(" 2.按姓名查询 \n");
printf("========================================\n");
printf(" 请 选 择: ");
p=head->next;
scanf("%d",&xz);
if(xz==1)
{
printf("请输入要查找的编号:");
scanf("%d",&n);
while(p&&p->data.num!=n)
p=p->next;
if(p==NULL||p->data.num>n){
p=NULL;
printf("没有找到");
}
}
else
if(xz==2)
{
printf("请输入要查找的姓名:");
scanf("%s",name);
while ((strcmp(p->data.name, name) != 0) && (p!=NULL))
p=p->next;
}
return p;
}
/*
**删除节点
*/
void DelNode(LinkList head)
{
char jx;
ListNode *p,*q;
p=ListFind(head);
if(p==NULL)
{
printf("没有找到");
return;
}
printf("真的要删除节点吗?(y/n): ");
//getchar();
scanf("%c",&jx);
if(jx=='y'||jx=='Y')
{
q=head;
while(q!=NULL&&q->next!=p)
q=q->next;
q->next=p->next;
free(p);
printf("通讯录已删除。\n");
}
}
/*
**输出函数
*/
void printList(LinkList head)
{
ListNode *p;
p=head->next;
printf("编号 姓名 性别 电话 地址\n");
printf("========================================\n");
while(p!=NULL){
printf("%d %s %s %s %s \n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
printf("========================================\n");
p=p->next;
}
}
/*
**修改通讯录
*/
void ChangeNode(LinkList head)
{
ListNode *p;
p=ListFind(head);
if(p!=NULL)
{
printf("编号 姓名 性别 电话 地址\n");
printf("========================================\n");
printf("%d %s %s %s %s \n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
printf("========================================\n");
printf("输入该通讯录者的正确的联系电话,通讯地址:\n 中间用空格隔开");
scanf("%s %s",p->data.phone,p->data.addr);
}
else
printf("没查到要修改的通讯录!\n");
}

2016-09-07 21:00
2016-09-09 08:11