c/c++语言开发共享使用结构不同的代码与c程序联系经理

现在我遇到了另一个问题,在我改变了如下所示的编码之后,它仍然显示出错误。 在编码内部,没有任何红色下划线,因此我无法找出错误的位置。 那么这个编码有什么错误吗?

struct contact { char name[20],email[20]; int hpnum; }add; int option; FILE *f; void addcontact(struct contact list[100]); void read(struct contact list[100]); int main (void) { struct contact list[100]; system("cls"); printf("==========Welcome to Jeffery's Contact System Management==========n"); printf("tttContact System Main Menun"); printf("[1] Create a New Contactn"); printf("[2] Modified Existing Contactn"); printf("[3] Delete Existing Contactn"); printf("[4] Search Existing Contactn"); printf("[5] Exitn"); printf("Please enter one of your option.n"); scanf("%d",&option); switch(option) { //add new contact case 1:addcontact(list);read(list); break; } getch(); } void addcontact(struct contact list[100]) { char name[20],email[20]; int hpnum,no; printf("nContact Name: "); scanf("%s",list[no-1].name); fflush(stdin); printf("nHandphone Number: "); scanf("%d",&list[no-1].hpnum); fflush(stdin); printf("nE-mail: "); scanf("%s",list[no-1].email); } void read(struct contact list[100]) { FILE *f; f=fopen("contact.txt","w"); fwrite(list,sizeof(list),100,f); fclose(f); } 

    首先, fflush(stdin); 是未定义的错误。 应该使用fflush(stdout);

    其次,在函数addcontact(struct contact list[100])变量no中没有分配任何值,并且你在scanf()函数中使用垃圾值。

    read()函数fwrite(list,sizeof(list),100,f); 这应该是错的。

     fwrite(list, sizeof(struct contact), 100, f); 

    我不确定,但它看起来你打算阅读多个联系人所以你还需要一个循环机制可能在addcontact()函数内

      以上就是c/c++开发分享使用结构不同的代码与c程序联系经理相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/522255.html

      (0)
      上一篇 2020年12月9日
      下一篇 2020年12月9日

      精彩推荐