| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1707 人关注过本帖
标题:重新打开程序后,可以打开保存的文件,但不能对其进行修改删除等操作,求大 ...
只看楼主 加入收藏
w2216599
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-5-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
重新打开程序后,可以打开保存的文件,但不能对其进行修改删除等操作,求大手帮忙
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>
#define password "9207"
#define MAX 100
typedef struct Student{            //链表的数据结构
     char number[20] ;//学号
     char name[20] ;//姓名
     int age;
     char grad[20] ;//年级
     char profess[30] ;//专业
     int times[5] ;//入学时间
     struct Student *next ;  
}Student,*LinkList;

void CreateList(LinkList &T)
{        //初始化链表
    T = (LinkList)malloc(sizeof(Student)) ;//头结点
    T->next = NULL;
         
}

void print(LinkList T){    //把链表的数据输出
     LinkList p = T ;
     int j=0 ;
     if(p->next){
         while(p->next){
             p = p->next ;
             printf("***********************************\n");
             printf("学号为:%s\n",p->number);
             printf("姓名为:%s\n",p->name);
             printf("年龄为:%d\n",p->age);
             printf("年级为:%s\n",p->grad);
             printf("专业为:%s\n",p->profess);
             printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
             printf("***********************************\n");

         }
     }else{
         printf("没有数据可输出!!!\n") ;
     }
 }

 void RearInsert(LinkList &T){        //尾插入结点
     char chars[4][20];
     int times[3] ;
     int age;
     LinkList p = T;
     printf("请输入要添加的记录: \n") ;
     printf("\n请以(学号 姓名 年龄  年级 专业 入学年 月 日)的形式输入学生资料: \n") ;
                 scanf("%s %s %d %s %s %d %d %d",chars[0],chars[1],&age,chars[2],chars[3],&times[0],&times[1],&times[2]) ;
     while(p->next){    //找到最后一个结点
        p=p->next ;
     }
     LinkList q = (LinkList)malloc(sizeof(Student)) ;//初始化一个新的节点
     strcpy(q->number,chars[0]) ;strcpy(q->name,chars[1]) ; strcpy(q->grad,chars[2]) ;strcpy(q->profess,chars[3]) ;
     q->age=age;
     q->times[0] = times[0] ;
     q->times[1] = times[1] ;
     q->times[2] = times[2] ;
     p->next = q ;
     q->next = NULL ;
     //printf("添加后的记录显示为: \n") ;
     //print(T) ;
 }

 void NumberDelete(LinkList &T){    //删除给出学号的结点,找不到则不做任何操作
     char number[20] ;
     LinkList p = NULL ;
     LinkList q = NULL ;
     printf("\n请输入要删除的学号 :") ;
     scanf("%s",number) ;
     if(T->next)
     {
         p=T;
         if (T->next->next==NULL&&strcmp(T->next->number,number)==0){
             free(T->next) ;
             T->next =NULL ;
             return ;        //删了就跳出函数
        }
         while (p->next){
             if (strcmp(p->next->number,number)==0){
                 LinkList q = p->next ;        //记录下p->next结点
                 p->next = q ->next ;
                 free(q) ;
                 return ;        //删了就跳出函数
             }
             p = p->next ;        
         }//while
         printf("没有可删除的学号!!!") ;
     }
     else
         printf("链表为空,没有可删数据了!!!!!");
 }


void NameDelete(LinkList &T){    //删除给出姓名的结点,找不到则不做任何操作
     char name[20] ;
     printf("\n请输入要删除的姓名 :") ;
     scanf("%s",name) ;
     if (T->next){
         
         LinkList p = T ;
         if (T->next->next==NULL&&strcmp(T->next->name,name)==0){
             free(T->next) ;
             T->next =NULL ;
             return ;        //删了就跳出函数
        }
         while (p->next){
             if (strcmp(p->next->name,name)==0){
                 LinkList q = p->next ;        //记录下p->next结点
                p->next = q ->next ;
                 free(q) ;
                 return ;        //删了就跳出函数
            }
             p = p->next ;        
         }//while
         printf("没有可删除的姓名!!!") ;
         
     }else
         printf("链表为空,没有可删数据了!!!!!") ;
 }

void Delete(LinkList &T){        //调用上面两个删除函数
     int n=0 ;
     system("cls");
     printf("请选择删除的方法: \n") ;
     printf("1.按学号删除   2.按姓名删除");
     scanf("%d",&n) ;
     if (n==1){
         NumberDelete(T) ;
     }
     if (n==2){
         NameDelete(T) ;
     }
     printf("\n删除后的学生记录为: \n") ;
     print(T) ;
 }

 void SeachNumber(LinkList T){    //按学号查找并修改
    if (T->next==NULL){
         printf("链表为空没有数据!!!\n") ;
         return  ;
     }
     int n,m;
     char chars[20],number[20] ;
     int times=0 ;
     LinkList p = T ;
     printf("\n请输入要修改的学生的学号 :") ;
     scanf("%s",number) ;
     while (p->next){               
             p=p->next ;
             if (strcmp(p->number,number)==0){   
                 printf("***********************************\n");
                 printf("找到的资料为:\n") ;
                 printf("***********************************\n");
                 printf("学号为:%s\n",p->number);
                 printf("姓名为:%s\n",p->name);
                 printf("年龄为:%d\n",p->age);
                 printf("年级为:%s\n",p->grad);
                 printf("专业为:%s\n",p->profess);
                 printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
                 printf("***********************************\n");

                 do{                    
                     printf("------------------------\n") ;
                     printf("    你真的要修改吗?        \n") ;
                     printf("    1.修改学号       2.修改姓名    \n") ;
                     printf("    3.修改年龄       4.修改年级    \n") ;
                     printf("    5.修改专业       6.修改入学年份    \n") ;
                     printf("    7.修改入学月份   8.修改入学日期  \n") ;
                     printf("    0.退出修改            \n") ;        
                     printf("------------------------\n") ;
                     printf("输入你要选择的操作:\n ");
                     scanf("%d",&n) ;
                     printf("\n\n");
                     switch(n){
                         case 1: printf("学号改为: ") ;scanf("%s",chars) ;strcpy(p->number,chars) ;break ;
                         case 2: printf("姓名改为: ") ;scanf("%s",chars) ;strcpy(p->name,chars) ;break ;
                         case 3: printf("年龄改为: ") ;scanf("%d",&m) ;p->age=m ;break ;
                         case 4: printf("年级改为: ") ;scanf("%s",chars) ;strcpy(p->grad,chars) ;break ;
                         case 5: printf("专业改为: ") ;scanf("%s",chars) ;strcpy(p->profess,chars) ;break ;
                         case 6: printf("入学年份改为: ") ;scanf("%d",&times) ;p->times[0] = times ;break ;
                         case 7: printf("入学月份改为: ") ;scanf("%d",&times) ;p->times[1] = times ;break ;
                         case 8: printf("入学日期改为: ") ;scanf("%d",&times) ;p->times[2] = times ;break ;
                         case 0: return ;
                         default: printf("请正确输入指定操作!!!");break ;
                     }
                     printf("***********************************\n");
                     printf("\n修改改后的学生信息为: \n") ;
                     printf("学号为:%s\n",p->number);
                     printf("姓名为:%s\n",p->name);
                     printf("年龄为:%d\n",p->age);
                     printf("年级为:%s\n",p->grad);
                     printf("专业为:%s\n",p->profess);
                     printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
                     printf("***********************************\n");
                 }while (1);
             }            
     }
         printf("找不到数据!!!") ;
 }

void SeachName(LinkList T){    //按姓名查找并修改
    if (T->next==NULL){
         printf("链表为空没有数据!!!\n") ;
         return  ;
     }
     int n,m;
     char chars[20],name[20] ;
     int times=0 ;
     LinkList p = T ;
     printf("\n请输入要修改的学生的姓名 :") ;
     scanf("%s",name) ;
     while (p->next){               
             p=p->next ;
             if (strcmp(p->name,name)==0){   
                 printf("***********************************\n");
                 printf("找到的资料为: \n") ;
                 printf("***********************************\n");
                 printf("学号为:%s\n",p->number);
                 printf("姓名为:%s\n",p->name);
                 printf("年龄为:%d\n",p->age);
                 printf("年级为:%s\n",p->grad);
                 printf("专业为:%s\n",p->profess);
                 printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
                 printf("***********************************\n");


                 do{                    
                     printf("------------------------\n") ;
                     printf("         你真的要修改吗?        \n") ;
                     printf("    1.修改学号       2.修改姓名    \n") ;
                     printf("    3.修改年龄       4.修改年级    \n") ;
                     printf("    5.修改专业       6.修改入学年份    \n") ;
                     printf("    7.修改入学月份   8.修改入学日期  \n") ;
                     printf("    0.退出修改            \n") ;        
                     printf("---------------------------------------\n") ;
                     printf("输入你要选择的操作: ");
                     scanf("%d",&n) ;
                     printf("\n\n");
                     switch(n){
                         case 1: printf("学号改为: ") ;scanf("%s",chars) ;strcpy(p->number,chars) ;break ;
                         case 2: printf("姓名改为: ") ;scanf("%s",chars) ;strcpy(p->name,chars) ;break ;
                         case 3: printf("年龄改为: ") ;scanf("%d",&m) ;p->age=m ;break ;
                         case 4: printf("年级改为: ") ;scanf("%s",chars) ;strcpy(p->grad,chars) ;break ;
                         case 5: printf("专业改为: ") ;scanf("%s",chars) ;strcpy(p->profess,chars) ;break ;
                         case 6: printf("入学年份改为: ") ;scanf("%d",&times) ;p->times[0] = times ;break ;
                         case 7: printf("入学月份改为: ") ;scanf("%d",&times) ;p->times[1] = times ;break ;
                         case 8: printf("入学日期改为: ") ;scanf("%d",&times) ;p->times[2] = times ;break ;
                         case 0: return ;
                         default: printf("请正确输入指定操作!!!");break ;
                     }
                     printf("***********************************\n");
                     printf("\n修改后的学生信息为: \n") ;
                     printf("***********************************\n");
                     printf("学号为:%s\n",p->number);
                     printf("姓名为:%s\n",p->name);
                     printf("年龄为:%d\n",p->age);
                     printf("年级为:%s\n",p->grad);
                     printf("专业为:%s\n",p->profess);
                     printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
                     printf("***********************************\n");
                 }while (1);
             }            
         }
       printf("找不到数据!!!") ;
 }
void Revise(LinkList &T){    //修改函数,调用上面两个函数
    int n=0 ;
    system("cls");
    printf("请选择修改的方法: 1.按学号查找并修改 2.按姓名查找并修改 : ") ;scanf("%d",&n) ;
    if (n==1){
        SeachNumber(T) ;
    }
    if (n==2){
        SeachName(T) ;
    }
 }
 void SeachByNumber(LinkList T){    //按学号查找
    if (T->next==NULL){
         printf("链表为空没有数据!!!\n") ;
         return  ;
     }
     char number[20] ;
     LinkList p = T ;
     printf("\n请输入要修改的学生的学号 :") ;
     scanf("%s",number) ;
     while (p->next){               
             p=p->next ;
             if (strcmp(p->number,number)==0){   
                 printf("***********************************\n");
                 printf("找到的学生信息为:\n\n") ;
                 printf("***********************************\n");
                 printf("学号为:%s\n",p->number);
                 printf("姓名为:%s\n",p->name);
                 printf("年龄为:%d\n",p->age);
                 printf("年级为:%s\n",p->grad);
                 printf("专业为:%s\n",p->profess);
                 printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
                 printf("***********************************\n");
             }
     }
      printf("找不到数据!!!");
        
 }

void SeachByName(LinkList T){    //按姓名查找
    if (T->next==NULL){
         printf("链表为空没有数据!!!\n") ;
         return  ;
     }
     char name[20] ;
     int times=0 ;
     LinkList p = T ;
     printf("\n请输入要修改的学生的姓名 :") ;
     scanf("%s",name) ;
     while (p->next){               
             p=p->next ;
             if (strcmp(p->name,name)==0){   
                 printf("***********************************\n");
                 printf("找到的学生信息为: \n") ;
                 printf("***********************************\n");
                 printf("学号为:%s\n",p->number);
                 printf("姓名为:%s\n",p->name);
                 printf("年龄为:%d\n",p->age);
                 printf("年级为:%s\n",p->grad);
                 printf("专业为:%s\n",p->profess);
                 printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
                 printf("***********************************\n");
             }   
         }
      printf("找不到数据!!!");
 }

void Search(LinkList &T){    //修改函数,调用上面两个函数
    int n=0 ;
    system("cls");
    printf("请选择查找的方法: 1.按学号查找 2.按姓名查找 : ") ;scanf("%d",&n) ;
    if (n==1){
        SeachByNumber(T) ;
    }
    if (n==2){
        SeachByName(T) ;
    }
 }

 void Write(LinkList T){  //写入文件
     FILE *fp ;
     LinkList p = T->next;
     char stud[20] ;
     printf("请输入保存文件名: ") ;
     scanf("%s",stud) ;
     if((fp=fopen(stud,"w"))==NULL){
         printf("无法打开文件!!!") ;
         fclose(fp) ;
         return ;        //退出函数
    }
     printf("\n你存入的数据为: \n") ;
     while (p){
         fprintf(fp,"%s %s %d %s %s %d %d %d\n",
                     p->number,p->name,p->age,p->grad,p->profess,p->times[0],p->times[1],p->times[2]) ;  
         printf("***********************************\n");
         printf("学号为:%s\n",p->number);
         printf("姓名为:%s\n",p->name);
         printf("年龄为:%d\n",p->age);
         printf("年级为:%s\n",p->grad);
         printf("专业为:%s\n",p->profess);
         printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
         printf("***********************************\n");
         p = p->next ;
     }
     fclose(fp) ;
 }
void Read(){        //读取文件
     FILE *out ;
     LinkList p = (LinkList)malloc(sizeof(Student)) ;//新建一个链表来存放读取的数据
     p->next = NULL ;
     char stud[20] ;
     printf("请输入要打开的文件名: ") ;
     scanf("%s",stud) ;
     if((out=fopen(stud,"r"))==NULL){
         printf("无法打开文件!!!") ;
         fclose(out) ;
         return ;        //退出函数
    }
     printf("\n文件数据为: \n") ;
     while(!feof(out))//检测流上的文件结束符
     {
         fscanf(out,"%s %s %d %s %s %d %d %d\n",
                     p->number,p->name,&p->age,p->grad,p->profess,&p->times[0],&p->times[1],&p->times[2])    ;   
         printf("***********************************\n");
         printf("学号为:%s\n",p->number);
         printf("姓名为:%s\n",p->name);
         printf("年龄为:%d\n",p->age);
         printf("年级为:%s\n",p->grad);
         printf("专业为:%s\n",p->profess);
         printf("入学时间为:%4d,%.2d,%.2d\n",p->times[0],p->times[1],p->times[2]);
         printf("***********************************\n");
     }
     fclose(out) ;   
 }


 void ReadAndSave(LinkList &T){    //显示,保存
     int n=0 ;
     printf("现在有数据: \n") ;
     print(T) ;
     printf("\n请选择; 1.保存数据 2.打开数据") ;
     scanf("%d",&n) ;
     if (n==1)Write(T) ;
     if (n==2)Read() ;
     if (n!=1&&n!=2)printf("输入错误!!!") ;
 }
 void Enter(){        //密码函数
     char number[20];
     int j=0;
     printf("请输入密码: ") ;
     while(number[j]=getch())
     {

         if(number[j]==13)
         {
             break;
         }
         else
         {
             printf("*");
             j++;
         }
         number[j]='\0';
    if (strcmp(number,password)==0)
      {
         system("cls");
         printf("\n");
         printf("  欢迎进入系统 \n") ;
         return ;
    }
     }
     exit(1);
 }

 void main(){
     int c ;
     Enter() ;   
     LinkList T ;
     CreateList(T) ;   
     system("color 1a");
     do{
         //system("cls");
         printf("--------------------------------\n") ;
         printf("    学生信息管理系统            \n") ;
         printf("    1.添加记录                    \n") ;
         printf("    2.删除记录                    \n") ;
         printf("    3.修改记录                    \n") ;
         printf("    4.显示、保存记录            \n") ;
         printf("    5.查询功能                    \n") ;
         printf("    6.输出全部                    \n") ;
         printf("    0.退出系统                    \n") ;        
         printf("--------------------------------\n") ;        
         printf("输入你要选择的操作: \n");
         scanf("%d",&c) ;        
         switch (c){
         case 1: RearInsert(T) ;break ;
         case 2:    Delete(T) ;break ;
         case 3:    Revise(T) ;break ;
         case 4:    ReadAndSave(T) ;break ;
         case 5:    Search(T);break;
         case 6: print(T) ;break ;
         case 0: return ;
         default :printf("请正确输入!!") ;break ;
         }
         putchar(10) ;
         getchar() ;
     }while (1);
 }



求大手帮忙改改,能实现重新打开程序,选择读取文件后能进行对其的修改、删除等操作
搜索更多相关主题的帖子: password include number 姓名 
2014-05-15 17:06
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:7 
在哪找的代码呀

总有那身价贱的人给作业贴回复完整的代码
2014-05-15 17:08
w2216599
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-5-15
收藏
得分:0 
在论坛上找的自己加了点东西  写大学毕业论文要用
2014-05-15 17:13
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:7 
用别人的代码  总是觉得似似而非   所以在添加自己的枝和叶时  是很难融合的

DO IT YOURSELF !
2014-05-15 17:19
top398
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:427
专家分:857
注 册:2014-5-2
收藏
得分:0 
既然不是自己的代码,建议反复运行和调试。
2014-05-15 18:47
杨攀好
Rank: 2
等 级:论坛游民
威 望:1
帖 子:41
专家分:32
注 册:2014-3-24
收藏
得分:0 
写代码不自己写   这么长的代码谁可能去帮你检查
2014-05-15 23:20
快速回复:重新打开程序后,可以打开保存的文件,但不能对其进行修改删除等操作, ...
数据加载中...
 
   



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

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