| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 762 人关注过本帖
标题:sleep()为什么修改后还是不行???
只看楼主 加入收藏
无情飞雪
Rank: 1
来 自:台州
等 级:新手上路
帖 子:10
专家分:4
注 册:2012-3-21
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:12 
sleep()为什么修改后还是不行???
这是一个用c语言写的通讯录,最后编译的时候有个错误:'sleep' undefined; assuming extern returning int
后来上搜索了一下,知道要在前面加#include<windows.h>,但添加后还是不行,为什么?????
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>


                                                                                                                                             
void storage();                //建立用户记录表
void add();                    //添加用户记录函数
void del();                    //删除用户记录函数
void search();                 //查找用户记录函数
void change();                 //查找用户记录函数
void print();                  //打印用户记录函数
void printt();                 //显示主菜单函数
void yanshi();                 //延时函数
void help();                   //关于此系统介绍的函数
void quit1();                  //自动返回主菜单函数
void quit2();                  //按任意键返回主菜单函数
int m = 0;
struct people
{
        char *name;
        char *tell;
        struct people *next;
};
struct people *head;
                                                                                                                                               
int main()
{
        char s;
        int i = 0;
        printf("\033[2J");
        printt();
do
        {
        scanf("%c",&s);
        if(s == 'j')    storage();
        else if(s == 't')       add();
        else if(s == 's')       del();
        else if(s == 'g')       change();
        else if(s == 'c')       search();
        else if(s == 'd')       print();
        else if(s == 'h')       help();
        else if(s == 'q')       i = 1;
        else    printf("输入错误\n");
        }while(i == 0);
        printf("您已退出系统!\n");
                                                                                                                                               
}
                                                                                                                                               
void printt()
{
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("|        主菜单:          |\n");
        printf("|                          |\n");
        printf("|     建立用户记录:(j)     |\n");
        printf("|                          |\n");
        printf("|     添加用户记录:(t)     |\n");
        printf("|                          |\n");
        printf("|     查找用户记录:(c)     |\n");
        printf("|                          |\n");
        printf("|     删除用户记录:(s)     |\n");
        printf("|                          |\n");
        printf("|     更改用户记录:(g)     |\n");
        printf("|                          |\n");
        printf("|     查看所有用户记录:(d) |\n");
        printf("|                          |\n");
        printf("|     关于此系统:(h)       |\n");
        printf("|                          |\n");
        printf("|     退出系统:(q)         |\n");
        printf("|                          |\n");
        printf("============================\n");
}
                                                                                                                                               
                                                                                                                                               
void help()    //关于系统介绍
{
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("|此系统是在链表的基础上建立|\n");
        printf("|的,所以退出系统就会丢失所|\n");
        printf("|有数据,本系统只为练习c语 |\n");
        printf("|言指针、链表所编写。请大家|\n");
        printf("|多多提意见!               |\n");
        printf("|           制作者:jc.mima|\n");
        printf("|           QQ:594216070 |\n");
        printf("============================\n");
        printf("\n按任意键回到主菜单");
        quit2();
}
                                                                                                                                               
void storage()     //建立用户记录表
{
        int n,i;
        struct people *p,*p1,*p2;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("|建立用户记录:             |\n\n");
        printf("要添加的用户数:");
        scanf("%d",&n);
        if(n < 100 && n > 0)
        {
                p = (struct people *)malloc(sizeof(struct people));
                p2 = (struct people *)malloc(sizeof(struct people));
                for(i = 0; i < n;i ++)
                {
                p1 = (struct people *)malloc(sizeof(struct people));
                if(i) ;
                else
                p = p1;
                printf("姓名:");
                p1->name = (char *)malloc(14);
                scanf("%s",p1->name);
                printf("%s 的电话号码:",p1->name);
                p1->tell = (char *)malloc(14);
                scanf("%s",p1->tell);
                p2->next = p1;
                p2 = p1;
                p1->next = NULL;
}
                  head = p;
        printf("添加成功  三秒后将自动回到主菜单");
        }
        else printf("添加未成功  三秒后将自动回到主菜单");
        printf("\n");
        quit1();
}
                                                                                                                                               
                                                                                                                                               
                                                                                                                                               
void add()                  //添加用户记录
{
        int i,n;
        struct people *p,*p1,*p2,*p3;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 添加用户记录:            |\n\n");
        printf("要添加的用户数:");
        scanf("%d",&n);
        if(n > 0 && n < 100)
        {
                if(head == NULL)
                {
                        p = (struct people *)malloc(sizeof(struct people));
                        p1 = (struct people *)malloc(sizeof(struct people));
                         for(i = 0; i < n; i ++)
                        {
                                p2=(struct people *)malloc(sizeof(struct people));
                                if(i)   ;
                                else p = p2;
                                printf("请输入姓名:");
                                p2->name = (char *)malloc(14);
                                scanf("%s",p2->name);
                                printf("请输入号码:");
                                p2->tell = (char *)malloc(14);
                                scanf("%s",p2->tell);
                                p1 = p2;
                                p1->next = p2;
                                p2->next = NULL;
                        }
                        head = p;
                        printf("添加成功! 3秒后将自动回到主菜单");
                }
                 else
                {
                        p3 = (struct people *)malloc(sizeof(struct people));
                        p3 = head;
                        while(p3->next != NULL)
                        {
                                p3 = p3->next;
                        }
                         p = (struct people *)malloc(sizeof(struct people));
                         p2 = (struct people*)malloc(sizeof(struct people));
                         for(i = 0; i < n; i ++)
                                 {
                                p1=(struct people *)malloc(sizeof(struct people));
                                if(i)   ;
                                else    p = p1;
                                printf("请输入姓名:");
                                p1->name = (char *)malloc(14);
                                scanf("%s",p1->name);
                                printf("请输入号码:");
                                p1->tell = (char *)malloc(14);
                                scanf("%s",p1->tell);
                                p2->next = p1;
                                p2 = p1;
                                p1->next = NULL;
                        }
                                 p3->next = p;
                                 printf("添加成功! 3秒后将自动回到主菜单");
                }
        }
        else printf("输入错误 3秒后将自动回到主菜单");
        printf("\n");
        quit1();
}



void print()   //打印用户记录函数
{
        struct people *p;
        int i;
        p = head;
                if(head != NULL)
                {
                        printf("\033[2J");
                        printf("=============通讯录========\n");
                        printf("|                          |\n");
                        printf("|                          |\n");
                        printf("|  所有用户记录:           |\n");
                        do
                        {
                                printf("|  %-12s            |\n",p->name);
                                printf("|  %-12s            |\n",p->tell);
                                p = p->next;
                        }while(p != NULL);
                printf("|                          |\n");
                printf("|                          |\n");
                printf("============================\n");
                printf("\n按任意键回到主菜单");
                quit2();
                }
                else
                        {
                        printf("\033[2J");
                        printf("=============通讯录========\n");
                        printf("|                          |\n");
                        printf("| 没有用户记录!            |\n");
                        for(i = 0; i < 3; i ++)
                        printf("|                          |\n");
                        printf("============================\n");
                        printf("\n按任意键回到主菜单");
                        quit2();
                }
}


void del()          //删除用户记录函数
{
        char *a;
        void deln();
        void delt();
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 删除用户记录:            |\n\n");
        printf("按名字删除(n)\n按号码删除(其它):");
        a = (char *)malloc(sizeof(char));
        scanf("%s",a);
        if(*a == 'n')
                deln();
        else delt();
                                                                                                                                               
}
void deln()          //删除用户记录函数(按用户姓名)
{
        struct people *p1,*p2;
        char *name;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("|删除用户记录(按用户姓名): |\n\n");
        printf("要删除用户的姓名:");
        name=(char *)malloc(14);
        scanf("%s",name);
        if(head != NULL)
                        {
                p1 = head;
                while(strcmp(name,p1->name) != 0 && p1->next != NULL)
                        {p2 = p1; p1 = p1->next;}
                if(strcmp(name,p1->name) == 0)
                        {
                        if(p1 == head)  head = p1->next;
                        else p2->next = p1->next;
                        printf("删除成功 三秒后将自动回到主菜单");
                        printf("\n");
                        quit1();
                        }
                else
                {
                        printf("没有记录 三秒后将自动回到主菜单\n");
                        quit1();
                }
                m --;
        }
        else
        {
                printf("没有记录 三秒后将自动回到主菜单\n");
                quit1();
        }
                                                                                                                                               
}
                                                                                                                                               
void delt()          //删除用户记录函数
{
        struct people *p1,*p2;
        char *tell;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 删除用户记录(按号码):    |\n\n");
        printf("要删除的号码:");
        tell = (char *)malloc(14);
        scanf("%s",tell);
        if(head != NULL)
           {
                p1 = head;
                while(strcmp(tell,p1->tell) != 0 && p1->next != NULL)
                        {p2 = p1; p1 = p1->next;}
                if(strcmp(tell,p1->tell) == 0)
                        {
                        if(p1 == head)  head = p1->next;
                        else p2->next = p1->next;
                        printf("删除成功 三秒后将自动回到主菜单 ");
                        printf("\n");
                        quit1();
                        }
                else
                {
                        printf("没有记录 三秒后将自动回到主菜单\n");
                        quit1();
                }
        }
        else
        {
                printf("没有记录 三秒后将自动回到主菜单\n");
                quit1();
        }
                                                                                                                                               
}
void search()    //查找用户记录函数
{
                                                                                                                                               
        char *a;
        void searcht();
        void searchn();
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 查找用户记录:            |\n\n");
        printf("按名字名字查询(n)\n按电话号码查询(其它):");
        a=(char *)malloc(sizeof(char));
        scanf("%s",a);
        if(*a == 'n')
                searchn();
        else searcht();
                                                                                                                                               
}
                                                                                                                                               
                                                                                                                                               
                                                                                                                                               
void searchn()    //查找用户记录函数 (按姓名)
{
struct people *p1,*p2;
        char *name;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 查找用户记录(按姓名):  |\n\n");
        printf("要查找的用户名:");
        name = (char *)malloc(14);
        scanf("%s",name);
        if(head!=NULL)
                        {
                p1=head;
                while(strcmp(name,p1->name)!=0&&p1->next!=NULL)
                        {p2=p1; p1=p1->next;}
                if(strcmp(name,p1->name)==0)
                {               printf("姓名:%s  电话号码:%s\n",p1->name,p1->tell);
                                printf("\n按任意键回到主菜单");
                                quit2();
                }
                else
                {
                        printf("未找到! 三秒后将自动回到主菜单");
                        quit1();
                }
        }
        else {printf("没有记录 三秒后将自动回到主菜单");
                 quit1();}
                                                                                                                                               
}
void searcht()    //查找用户记录函数 (按电话号码)
{
        struct people *p1,*p2;
        char *tell;
        void yanshi();
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("|查找用户记录(按电话号码): |\n\n");
        printf(" 电话号码:");
        tell=(char *)malloc(14);
        scanf("%s",tell);
        if(head!=NULL)
                        {
                p1=head;
                while(strcmp(tell,p1->tell)!=0&&p1->next!=NULL)
                        {p2=p1; p1=p1->next;}
                if(strcmp(tell,p1->tell)==0)
                {               printf("姓名:%s  电话号码:%s\n",p1->name,p1->tell);
                                printf("\n按任意键回到主菜单");
                                quit2();
                }
                else
                {
                        printf("未找到! 三秒后将自动回到主菜单");
                        quit1();
                }
        }
        else {printf("没有记录 三秒后将自动回到主菜单");
                 quit1();}
}
                                                                                                                                               
                                                                                                                                               
                                                                                                                                               
void change()        //更改用户记录函数
{
        char *a;
        void changet();
        void changen();
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 更改用户记录:            |\n\n");
        printf("更改用户姓名(n) 更改用户号码(其它)");
        a=(char *)malloc(sizeof(char));
        scanf("%s",a);
        if(*a=='n')
                changen();
        else changet();
}
void changet()    //更改用户记录函数(更改电话号码)
{
        struct people *p1,*p2;
        char *name,*tell;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 更改用户记录(更改号码):  |\n\n");
        printf("要更改的用户名:");
        name=(char *)malloc(14);
        scanf("%s",name);
        if(head!=NULL)
                        {
                p1=head;
                while(strcmp(name,p1->name)!=0&&p1->next!=NULL)
                        {p2=p1; p1=p1->next;}
                if(strcmp(name,p1->name)==0)
                {               printf("姓名:%s  电话号码:%s\n",p1->name,p1->tell);
                                printf("电话号码改为:");
                                tell=(char *)malloc(14);
                                scanf("%s",tell);
                                p1->tell=tell;
                                printf("更改成功\n");
                                printf("按任意键回到主菜单");
                                quit2();
                }
                else
                {
                        printf("未找到! 三秒后将自动回到主菜单");
                        printf("\n");
                        quit1();
                }
        }
        else {printf("没有记录 三秒后将自动回到主菜单");
                printf("\n");
                 quit1();}
                                                                                                                                               
}
                                                                                                                                               
                                                                                                                                               
void changen()    //更改用户记录函数(更改姓名)
{
        struct people *p1,*p2;
        char *name,*tell;
        printf("\033[2J");
        printf("=========通讯系统===========\n");
        printf("|                          |\n");
        printf("| 更改用户记录(更改姓名):  |\n\n");
        printf("要更改的用户名:");
        tell=(char *)malloc(14);
        scanf("%s",tell);
        if(head!=NULL)
                        {
                p1=head;
                while(strcmp(tell,p1->tell)!=0&&p1->next!=NULL)
                        {p2=p1; p1=p1->next;}
                if(strcmp(tell,p1->tell)==0)
                {               printf("姓名:%s  电话号码:%s\n",p1->name,p1->tell);
                                printf("其姓名改为:");
                                name=(char *)malloc(14);
                                scanf("%s",name);
                                p1->name=name;
                                printf("更改成功\n");
                                printf("按任意键回到主菜单");
                                quit2();
                }
                else
                {
                        printf("未找到! 三秒后将自动回到主菜单");
                        printf("\n");
                        quit1();
}
        }
        else {printf("没有记录 三秒后将自动回到主菜单");
                printf("\n");
                 quit1();
                }
                                                                                                                                               
}
                                                                                                                                               
                                                                                                                                               
                                                                                                                                               
                                                                                                                                               
void quit1()
{
        getchar();
        printf("\n");
        printf("\033[2J");
        printt();
}
                                                                                                                                               
void quit2()
{
        getchar();
        sleep(3);
        getchar();
        printf("\n");
        printf("\033[2J");
        printt();
}
搜索更多相关主题的帖子: undefined include storage 通讯录 记录表 
2012-03-21 16:40
杨松松
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:98
专家分:142
注 册:2011-12-3
收藏
得分:2 
sleep是以毫秒为单位的,估计楼主设的时间太短了应该改成sleep(3000)
2012-03-21 16:44
喝醉的猫
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:68
专家分:120
注 册:2012-3-13
收藏
得分:0 
对我来说太长咯....不太会啊
2012-03-21 16:44
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:4 
试试把sleep(3)改成Sleep(3000)。

[ 本帖最后由 有容就大 于 2012-3-21 16:49 编辑 ]

梅尚程荀
马谭杨奚







                                                       
2012-03-21 16:48
徐子锦
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-3-21
收藏
得分:0 
  一看这么长脑袋晕。
2012-03-21 16:48
chenlei8509
Rank: 1
等 级:新手上路
帖 子:5
专家分:4
注 册:2011-12-7
收藏
得分:0 
在什么环境下?VC?
2012-03-21 16:53
chenlei8509
Rank: 1
等 级:新手上路
帖 子:5
专家分:4
注 册:2011-12-7
收藏
得分:0 
#include <windows.h>
2012-03-21 16:54
chenlei8509
Rank: 1
等 级:新手上路
帖 子:5
专家分:4
注 册:2011-12-7
收藏
得分:4 
Sleep(3),'S'大写?
2012-03-21 16:54
无情飞雪
Rank: 1
来 自:台州
等 级:新手上路
帖 子:10
专家分:4
注 册:2012-3-21
收藏
得分:0 
回复 6楼 chenlei8509
嗯,是的

[ 本帖最后由 无情飞雪 于 2012-3-21 18:20 编辑 ]
2012-03-21 18:17
无情飞雪
Rank: 1
来 自:台州
等 级:新手上路
帖 子:10
专家分:4
注 册:2012-3-21
收藏
得分:0 
回复 8楼 chenlei8509
这个有关系吗???
2012-03-21 18:17
快速回复:sleep()为什么修改后还是不行???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036159 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved