| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 522 人关注过本帖
标题:小型数据管理系统,求大神帮我找错误
取消只看楼主 加入收藏
高山流水tgy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-20
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
小型数据管理系统,求大神帮我找错误
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct student
{
    char no[15];
    char name[15];
    long int sum;
    long int   password;
    struct student *next;
}stu;
     //函数声明
    int menu_select();  
    struct student *input();
    void print(struct student *stud);
    void search(struct student *stud);
    struct student *insert(struct student *stud);
    struct student *deletel(struct student *stud);
    int save(struct student *stud);
    int load(struct student *stud);
/*********主函数开始**********/
int main()
{
    int n=0,m,j,x,password=666666;
    struct student *head;
    head=NULL;
    system("color 5e");
    system("cls");
/****输入密码******/
    printf("请输入密码:");
    scanf("%d",&m);
    if(m==password)
        printf("口令正确!\n");
    else
    {   
        {
            printf("密码不正确,还有2次机会。请重新输入:");
            scanf("%d",&j);
        }
        if(j==password)
            printf("口令正确!\n");
        else
        {
            {
                printf("密码不正确,还有1次机会。请重新输入:");
                scanf("%d",&x);
            }
              if(x==password)
                  printf("口令正确!\n");
              else
              {
                  printf("您是非法用户!\n");
                  exit(0);
              }
        }
    }
    for(;;)
    {
             switch(menu_select())
             {   
             case 1:head=input();break;
             case 2:print(head);break;
             case 3:search(head);break;
             case 4:insert(head);break;
             case 5:deletel(head);break;
             case 6:save(head);break;
             case 7:load(head);break;
             case 8:exit(0);
             }
     }
    return 0;
}
/*****菜单选择函数******/
 int menu_select()
 {
     char s[3];int c;
     printf("       *********主菜单*********\n");
     printf("           1.输入记录\n");
     printf("           2.显示所有记录\n");
     printf("           3.按学号查找记录并显示\n");
     printf("           4.插入记录\n");
     printf("           5.删除记录\n");
     printf("           6.将所有数据写入文件\n");
     printf("           7.从文件中读入所有记录\n");
     printf("           8.退出\n");
     printf("        *************************\n\n");
     do
     {   printf("     请选择操作(1-8)");
         scanf("%s",s);
     c=atoi(s);
     }while(c<0||c>9);
     return(c);
}
//输入函数
struct student *input(struct student *head)
{
    char temp;
    struct student *p1,*p2;
    p1=p2=(struct student*)malloc(sizeof(struct student));
    printf("exit:double times enter!\n");
        printf("\n请输入姓名:\n");
            scanf("%s",p1->no);
        printf("请输入学号:\n");
            scanf("%s",p1->name);
        printf("请输入总分:\n");
            scanf("%ld",&(p1->sum));
        printf("请输入密码:\n");
            scanf("%ld",&(p1->password));
    p1->next=NULL;
    while(strlen(p1->name)>0)
    {
        if(head==NULL)
            head=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct student*)malloc(sizeof(struct student));
        printf("exit:double times enter!\n");
        printf("\n请输入姓名:\n");
            scanf("%s",p1->no);
        printf("请输入学号:\n");
            scanf("%s",p1->name);
        printf("请输入总分:\n");
            scanf("%ld",&(p1->sum));
        printf("请输入密码:\n");
            scanf("%ld",&(p1->password));
        p1->next=NULL;
        printf("是否继续输入(y/Y)\n");
        getchar();
        scanf("%c",&temp);
        if(temp!='y'&&temp!='Y')
        break;
    }
    return (head);
}
//输出函数
void print(struct student *head)
{
    struct student *temp;
    temp=head;
    printf("\n output string:\n");
    for(temp=head;temp!=NULL;temp=temp->next)
    {
        printf("----输入学号为:%s\n----输入姓名为:%s\n----输入总分为:%ld\n----输入密码为:%ld\n",temp->no,temp->name,temp->sum,temp->password);
    }
    return;
}
//查询数据
void search(struct student *head)
{
    int flag=0;
    char s[15];
    struct student *temp;
    temp=head;
    printf("请输入要查询学生的姓名\n");
    scanf("%s",s);
    while(temp!=NULL)
    {
    if(strcmp(temp->name,s)==0)
    flag=1;
    temp=temp->next;
    }
    if(flag!=1)
    printf("\n您要查找的是%s,很遗憾,查无此人!\n",s);
    else
    {
        printf("**********Found***********\n");
        printf("学号   姓名    总分   密码\n");
        printf("---------------------------\n");
        printf(" %s %s %ld %ld\n",temp->no,temp->name,&(temp->sum),&(temp->password));
        printf("**************************\n");
    }
    return;
}
//插入数据
struct student *insert(struct student *head)
{
    char a[15],b[15];
    long int c,d,n;
    struct student *p1,*p2,*p3;
    p1=(struct student*)malloc(sizeof(struct student));
    scanf("%s\n%s\n%ld\n%ld\n",a,b,&c,&d);
    strcpy(p1->no,a);
    strcpy(p1->name,b);
    p1->sum=c;
    p1->password=d;
    n=atoi(a);
    p2=head;
    if(head==NULL)
    {
        head=p1;
        p1->next=NULL;
    }
    else
    {
        while(n>p2->no&&p2->next!=NULL)
        {
            p3=p2;
            p2=p2->next;
        }
        if(n<=p2->no)
            if(head==p2)
            {
                p1->next=p2;
                head=p1;
            }
            else
            {
                p1->next=p2;
                p3->next=p1;
            }
        else
        {
            p2->next=p1;
            p1->next=NULL;
        }
    }
    return(head);
}

//删除数据
struct student *deletel(struct student *head)
{
    char name1[15];
    struct student *temp,*p;
    temp=head;
    scanf("%s",name1);
    if(head==NULL)
        printf("\nList is NULL\n");
    else
    {
        temp=head;
        while(strcpy(temp->name,name1)!=0&&temp->next!=NULL)
        {
            p=temp;
            temp=temp->next;
        }
        if(strcpy(temp->name,name1)==0)
        {
            if(temp==head)
            {
                head=head->next;
                free(temp);
            }
        else
        {
            p->next=temp->next;
            printf("delede string:%s\n",temp->name);
            free(temp);
        }
        }
        else printf("\n no find string:");
    }
    return(head);
}
//将所有数据写入文件
int save(struct student *head)
{
    FILE *fp;
    struct student *temp;
    temp=head;
    if((fp=fopen("test.txt","w"))==NULL)
    {
        printf("cannot open file! \n");
        exit(0);
    }
    while(temp!=NULL)
    {
        printf(" %s %s %ld %ld\n",temp->no,temp->name,&(temp->sum),&(temp->password));
        fputs(temp->no,fp);
        fputs(temp->name,fp);
        fscanf(fp,"%ld%ld",&(temp->sum),&(temp->password));
    }
    fclose(fp);
    return 0;
}
//从文件中读入所有记录
int load(struct student *head)
{
    FILE *fp;
    struct student *temp;
    temp=head;
    if((fp=fopen("text.txt","r"))==NULL)
    {
        printf("cannot open file! \n");
        exit(0);
    }
    while(temp!=NULL)
    {
        fgets(temp->no,15,fp);
        fgets(temp->name,15,fp);
        fprintf(fp,"%ld%ld",&(temp->sum),&(temp->password));
    }
    fclose(fp);
    return 0;
}
有两个警告,但是能运行;
有如下功能:
!:菜单选择函数(选择操作的序号)
2:创建链表函数(用于输入每个学生的成绩)
3;输出链表函数(输出输入、插入、删除后的数据的链表数据)
4:查询某节点的数据函数
5:插入节点函数
6:删除节点函数
7:将数据写入文件
8:将文件内容显示到屏幕
9:退出

进入密码为:666666;
想要提的问题是:
1:输入的数据无法全部显示到频幕;
2;数据输入超过三个时,输出的东西一样;
3:插入或删除节点后,不能再次显示被刷新的数据;
4:数据读入文件不能成功,更不能显示:
5:不知道如何进行调试;
望各位大神指教
搜索更多相关主题的帖子: password 管理系统 include search insert 
2014-02-20 12:37
高山流水tgy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-20
收藏
得分:0 

-Configuration: dsfsdf - Win32 Debug--------------------
Compiling...
hsgdhfsdjk.c
C:\Program Files\Microsoft Visual Studio\MyProjects\dsfsdf\hsgdhfsdjk.c(197) : warning C4047: '>' : 'long ' differs in levels of indirection from 'char [15]'
C:\Program Files\Microsoft Visual Studio\MyProjects\dsfsdf\hsgdhfsdjk.c(202) : warning C4047: '<=' : 'long ' differs in levels of indirection from 'char [15]'

hsgdhfsdjk.obj - 0 error(s), 2 warning(s)
中文翻译:
-Configuration:dsfsdf - Win32调试- - - - - - - - - - - - - - - - - - - - -
编译…
hsgdhfsdjk.c
C:\ Program Files \ Microsoft Visual Studio \ \ dsfsdf \ hsgdhfsdjk.c MyProjects项目(197):警告C4047:“>”:“长”在不同水平的间接“char[15]”
C:\ Program Files \ Microsoft Visual Studio \ \ dsfsdf \ hsgdhfsdjk.c MyProjects项目(202):警告C4047:“< =”:“长”在不同水平的间接从“char[15]


hsgdhfsdjk.obj - 0错误(s),2警告(年代)
2014-02-21 08:14
高山流水tgy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-20
收藏
得分:0 
这个应该没多大的关系吧?
2014-02-21 08:15
快速回复:小型数据管理系统,求大神帮我找错误
数据加载中...
 
   



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

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