| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 383 人关注过本帖
标题:这个程序谁帮我看看?没有错误,但是目的达不到
只看楼主 加入收藏
裤头君
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
这个程序谁帮我看看?没有错误,但是目的达不到
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

#define N 10000
char sj[9][N];
int bh1;
int chuangjian();
void shanchu();
int chuangjian()
{
    char c='n';
    int i=0,bh1=0;
    FILE*fb;
    if((fb=fopen("人事.txt","wb+"))==NULL)
    {
        printf("can't open file\n");
        exit(1);
    }
    while(c=='N'||c=='n')
    {
        printf("请根据提示输入信息\n");
        printf("编号\n");
        scanf("%s,%s\n",&sj[0][bh1]);  getchar();
        printf("姓名\n");
        scanf("%s,%s\n",&sj[1][bh1]);  getchar();
        printf("性别\n");
        scanf("%s,%s\n",&sj[2][bh1]);  getchar();
        printf("出生年份\n");
        scanf("%s,%s\n",&sj[3][bh1]);  getchar();
        printf("参加工作年份\n");
        scanf("%s,%s\n",&sj[4][bh1]);  getchar();
        printf("工资\n");
        scanf("%s,%s\n",&sj[5][bh1]);  getchar();
        printf("学院\n");
        scanf("%s,%s\n",&sj[6][bh1]);  getchar();
        printf("职务\n");
        scanf("%s,%s\n",&sj[7][bh1]);  getchar();
        printf("学位\n");
        scanf("%s,%s\n",&sj[8][bh1]);  getchar();
        for(i=0;i<9;i++)
        fwrite(&sj[i][bh1],10,1,fb);
        bh1++;
        printf("是否返回(Y/N)\n");
        scanf("%c",&c);
    }
    fclose(fb);
    return(sj[0][bh1]);
}
void shanchu()
{
    char c='Y',m='Y',bh2;
    int i=0,j=0,k=0,bh1;
    FILE*fb;
    if((fb=fopen("人事.txt","rb+"))==NULL)
    {
        printf("can't open file\n");
        exit(1);
    }
    while(c=='Y'||c=='y')
    {
        printf("请输入被删除老师的编号:");
        scanf("%c",&bh2);
        getchar();
        printf("确定删除么?(Y/N)");
        m=getchar(); getchar();
        if(m=='Y'||m=='y')
            for(i=0;i<bh1;i++)
                if(sj[0][i]==bh2)
                {
                    k=i;
                    break;
                }
                if(k<0)
                printf("输入有误\n");
                for(i=k;i<bh1;i++)
                    for(j=0;j<9;j++)
                    sj[j][i]=sj[j][i+1];
                    for(i=0;i<9;i++)
                        for(j=0;j<bh1;j++)
                            fwrite(&sj[i][j],10,1,fb);
                bh1=bh1-1;
        printf("是否继续删除?(Y/N):");
        c=getchar();
    }

}
void main()
{
    while(1)
    {
        int q;
        printf("\n");
        printf("\t*************2.删除****************\n");
        printf("\t*************3.创建****************\n");
        printf("\t**********5.退出***********\n");
        scanf("%d",&q);
        switch(q)
        {
        case 2:shanchu();break;
        case 3:chuangjian();break;
        case 5:printf("谢谢使用,88\n");exit(1);
        default:printf("输入错误,请重新选择!\n");
        }
    }
}删除没法成功
搜索更多相关主题的帖子: void include file 
2011-06-22 22:20
红色警戒
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:19
帖 子:444
专家分:2967
注 册:2005-11-20
收藏
得分:20 
if((fb=fopen("人事.txt","rb+"))==NULL)
只读方式打开的吧

2011-06-23 18:29
快速回复:这个程序谁帮我看看?没有错误,但是目的达不到
数据加载中...
 
   



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

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