使用文件删除学生数据库程序中无效的功能

时间:2015-04-28 14:02:16

标签: c database file

它创建包含所需结果的临时文件。但它没有删除以前的文件" records.txt"而不是重命名temp.txt。即时通讯使用dev c ++。

void delete()
{
    FILE *fp, *ft;
    int no;
    char ch;
    student stud;

    fp = fopen("Records.txt","r");
    printf("\nEnter student's RollNo to delete:");

    scanf("%d",&no);
    ft = fopen("temp.txt","w+");

    while (!feof(fp))
    {
        fscanf(fp, "\n%d\t%s\t", &stud.roll_no, stud.name);
        if (stud.roll_no != no)
        {
            fprintf(ft, "\n\t%d \t%s", stud.roll_no, stud.name);
        }
    }
    fclose(fp);
    fclose(ft);

    remove("Records.txt");
    rename("temp.txt","Records.txt");
}

0 个答案:

没有答案