修改文件名
程序代码:void modify(int number) //修改
{
FILE * fp1;
int n=0;
if((fp = fopen("bookinfo.txt","r")) == NULL){
printf("File open error!\n");
exit(0);
}
while(!feof(fp))
{
for(;!feof(fp);){
fscanf(fp, "%d %s %s %f", &num, writer, name, &price);
if(number != num)
{
if((fp1 = fopen("temp.txt","a+"))==NULL){
printf("open error!\n"); exit(0);
}
fprintf(fp1, "%d %s %s %f ", num, writer, name, price);
fclose(fp1);
}
if(number == num)
n ++;
}
}
printf("请输入新图书编号");
scanf("%d", &num);
check(num);
printf("请输入新图书名:");
scanf("%s", name);
printf("请输入新图书作者:");
scanf("%s", writer);
printf("请输入新图书价格:");
scanf("%f", &price);
if((fp1 = fopen("bookinfo.txt","a+"))==NULL){
printf("open error!\n");
exit(0);
}
if(n == 0){
printf("无此图书!\n");
exit(0);
}
fprintf(fp1, "%d %s %s %f ", num, writer, name, price);
fclose(fp1);
fclose(fp);
wenjian(fp, fp1);
printf("修改完成!\n");
main();
}
void wenjian(FILE *fp, FILE *fp1)
{
system("rename bookinfo.txt temp1.txt");
system("rename temp.txt bookinfo.txt");
remove("temp1.txt");[local]1[/local]
}







