| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 728 人关注过本帖
标题:自己编写的小型文件管理系统
只看楼主 加入收藏
天羽101
Rank: 2
等 级:论坛游民
帖 子:8
专家分:11
注 册:2012-4-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
自己编写的小型文件管理系统
  刚学完c语言,有点兴奋,自己编写了一个小型文件管理系统,漏洞百出,求高手指点.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void Display(void)
{
    FILE *fp;
    char name[10], ch;
    printf("Input the file name:");
    scanf("%s",name);
    if((fp = fopen(name,"r")) == NULL)
    {
        printf("Cannot open the file!\n");
        exit(0);
    }
    while(!feof(fp))
    {
        ch = fgetc(fp);
        putchar(ch);
    }
    printf("\n");
    fclose(fp);
    return 0;
}
void Copy(void)
{
    FILE *in, *out;
    char namein[100], nameout[100], ch;
    printf("Input the file name:");
    scanf("%s", namein);
    printf("Input the arm file name:");
    scanf("%s", nameout);
    if((in = fopen(namein, "rb")) == NULL)
    {
        printf("Cannot open the file!\n");
        exit(0);
    }
    if((out = fopen(nameout, "wb")) == NULL)
    {
        printf("Cannot open the arm file!\n");
        exit(0);
    }
    while(!feof(in))
    {
        ch = fgetc(in);
        fputc(ch,out);
    }
    fclose(in);
    fclose(out);
    printf("Complete.");
    return 0;
}
void Connect(void)
{
    FILE *fp1, *fp2;
    char ch;
    char name1[100], name2[100];
    printf("Input the first file:");
    scanf("%s", name1);
    printf("Input the second file:");
    scanf("%s", name2);
    if((fp1 = fopen(name1, "rb")) == NULL)
    {
        printf("Cannot open the first file!");
        exit(0);
    }
    if((fp2 = fopen(name2, "ab")) == NULL)
    {
        printf("Cannot open the second file!");
        exit(0);
    }
    while(!feof(fp1))
    {
        ch = fgetc(fp1);
        fputc(ch,fp2);
    }
    printf("Connect OK!");
    fclose(fp1);
    fclose(fp2);
    return 0;
}
void Compare(void)
{
    FILE *fp1, *fp2;
    char s[100], t[100], name1[100], name2[100];
    printf("Input file one:");
    scanf("%s", name1);
    printf("Input file two:");
    scanf("%s", name2);
    if((fp1 = fopen(name1, "rb")) == NULL)
    {
        printf("Cannot open the file one!\n");
        exit(0);
    }
    if((fp2 = fopen(name2, "rb")) == NULL)
    {
        printf("Cannot open the file two!\n");
        exit(0);
    }
    fread(s, sizeof(FILE), 1, fp1);
    fread(t, sizeof(FILE), 1, fp2);
    if(strcmp(s,t) == 0)
        printf("The two file are equal!\n");
    else
        printf("The two file are not equal!\n");
    fclose(fp1);
    fclose(fp2);
    return 0;
}
void Delete(void)
{
    char name[100];
    printf("Input the file name:");
    scanf("%s", name);
    if(unlink(name) == 0)
        printf("delete the file OK!");
    printf("\n");
    return 0;
}
void Rename(void)
{
    char oldname[100], newname[100];
    printf("Input the old and the new name:");
    scanf("%s%s", oldname, newname);
    if(rename(oldname, newname) == 0)
        printf("Rename OK!\n");
    else    printf("Rename fault!\n");
    return 0;
}
main()
{
    int i;
    printf("****************MENU******************\n");
    printf(" 0.\tDisplay\tText\tFile\n");
    printf(" 1.\tCopy\tFile\n");
    printf(" 2.\tConnect\tFile\n");
    printf(" 3.\tCompare\tFile\n");
    printf(" 4.\tDelete\tFile\n");
    printf(" 5.\tRename\tFile\n");
    printf(" 6.\tQuit\n");
    printf("**************************************\n");
    printf("Enter your choice<0~7>:");
    scanf("%d", &i);
    switch(i)
    {
        case 0: Display();
        case 1: Copy();
        case 2: Connect();
        case 3: Compare();
        case 4: Delete();
        case 5: Rename();
        case 6: exit(0);
    }
}
搜索更多相关主题的帖子: void 文件管理 include return file 
2012-06-13 11:20
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:20 
你自己发现有什么漏洞?改了没有?

我们都在路上。。。。。
2012-06-13 11:31
快速回复:自己编写的小型文件管理系统
数据加载中...
 
   



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

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