函数实验实例
void ModifyFile() {
system("cls"); Menu1(); book stu; FILE *fp; char x[8]; printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("请输入图书id:"); scanf("%s", x); fp = fopen("book1.dat", "rb+"); if (fp == NULL) {
printf("文件打开失败"); exit(1); } fseek(fp, 0, SEEK_SET); while (fread(&stu, LEN, 1, fp)) {
if (strcmp(x, stu.id) == 0) {
printf("请重新输入图书id: "); scanf("%s", stu.id); printf("请重新输入书名: "); scanf("%s", stu.name); printf("请重新输入书籍作者 : "); scanf("%s", &stu.author); printf("请重新输入图书出版社 : "); scanf("%s", &stu.publish); printf("请重新输入图书价格 : "); scanf("%lf", &stu.price); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); fflush(stdin); fseek(fp, 0-LEN, SEEK_CUR); fwrite(&stu, LEN, 1, fp); fclose(fp); } if (feof(fp)) {
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("没有图书信息"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); } } system("pause"); system("cls"); return; }
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231446.html原文链接:https://javaforall.net
