C编程,删除函数

C编程,删除函数,c,fseek,C,Fseek,尝试使用fseek修改名称 但它不能返回我想要的结果,即名称不能修改并保持不变 struct phonebook { char name[20]; }; struct phonebook a; char temp[20]; cpPtr=fopen("name.txt","rb");//open the file while(fread(&a,sizeof(a),1,cpPtr)==1){ printf("Please enter name :\n");//require use

尝试使用fseek修改名称 但它不能返回我想要的结果,即名称不能修改并保持不变

struct phonebook { char name[20]; };
struct phonebook a;

char temp[20];
cpPtr=fopen("name.txt","rb");//open the file
while(fread(&a,sizeof(a),1,cpPtr)==1){
    printf("Please enter name :\n");//require user to enter name
    scanf("%s",&temp);//temporary variable
    fflush(stdin);
    if(stricmp(a.name,temp)==0){
        printf("NAME :%s\n",a.name);
        else
            printf("The name is not exist");
        getch();
    }

    printf("Please enter new NAME :");
    scanf("&s",a.name);
    fflush(stdin);
    fseek(cpPtr,-sizeof(a),SEEK_CUR);//is there any wrong with seek?
    fwrite(&a,sizeof(a),1,cpPtr);
    fclose(cpPtr);
    printf("Name is modified");
    getch();
    system("cls");
}

您打开该文件仅用于读取。如果要同时进行读写操作,则必须以读写模式打开文件

fopen("name.txt","r+b"); // open read+write

请阅读你的问题,看看你是否能理解你的问题。我当然不能。请告诉我们‘a’的定义。我正在使用fseek在文件中查找我的“姓名”,然后替换该姓名,但它无法构建电话簿{char name[20];};结构电话簿a;使用fflush(stdin);和scanf(…);[而不是fscanf(stdin);]使我的对称检测器颤抖。在我这么做之后,我也不能修改我的名字,它还保留相同的EADD调试语句,以查看程序正在做什么。