鱼C论坛

 找回密码
 立即注册
查看: 2907|回复: 2

C语言问题 为什么我这个函数不行 关于链表与文件的

[复制链接]
发表于 2015-12-18 19:23:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct friends{
       
        char name[50];  //姓名
        char sex[10];   //性别
        char telephone[15];  //电话号码
        char address[50];   //地址
        char wechat[50];    //微信
        char QQ[15];         //QQ号码
        struct friends *next;
};
int size=sizeof(struct friends);
void main()
{
        struct friends *create_link_table(struct friends *head);
        struct friends *edit_node(struct friends *head,char name1[]);
        void query_link_table();
        struct friends *head=NULL,*p=NULL,*list=NULL;

int s;
        int n;
        char name1[50];

int sel;
       
        while(1)
        {  
               
                system("cls");
                printf("========================================\n");
                printf("|---1.添加朋友信息----2.修改朋友信息---|\n");
                printf("|---3.查询朋友信息----4.删除朋友信息---|\n");
                printf("|---5.输出朋友信息----0.退出-----------|\n");
                printf("========================================\n");
                printf("请选择输入(1-5),输入0退出\n");
                scanf("%d",&sel);
                switch(sel)
                {
                case 1: //输入朋友信息
                       
                        p=create_link_table(head);
                        printf("\n按任意键继续");
                        getchar();
                        break;
                       
                case 2: //修改朋友信息
                        printf("请输入需要修改信息的朋友名字:\n");
                        list=edit_node(p,name1);
                        getchar();
                        break;
                       
                case 3:
                        query_link_table();
                        getchar();
                        break;

}
                system("pause");
               
        }

}
struct friends *edit_node(struct friends *head,char name1[])
{
       
        char name[50];  //姓名
    char sex[10];   //性别
    char telephone[15];  //电话号码
    char address[50];   //地址
    char wechat[50];    //微信
    char QQ[15];  //QQ号码
        FILE *f;
       
        int n=0;
        struct friends *p;
        p=head;
       
        //char ch[50];
        //char ah[50];
       
        if((f=fopen("朋友圈信息.txt","r"))==NULL)
        {
                printf("can not open the file");
                exit(0);
               
        }
           while(!feof(f))
        {
               
                fscanf(f,"%s%s%s%s%s%s",name,sex,telephone,address,wechat,QQ);
               
        }
        fclose(f);
       
           if((f=fopen("朋友圈信息.txt","w"))==NULL)
        {
               
                printf("can not open the file");
                exit(0);
               
        }
       
    while(p!=NULL)
        {
                if((strcmp(name1,p->name)!=0))
                        fprintf(f,"%-6s%6s%13s%10s%12s%12s",p->name,p->sex,p->telephone,p->address,p->wechat,p->QQ);
               
                if(n==0)
                {  
                        printf("重新写入地址\n");
                        scanf("%s",p->address);
                       
                }
               
                p=p->next;
        }
        fclose(f);
        return head;
}
请大神 细心一点看 这个函数是用来修改想要修改的文件内容,运用链表的方式 求大神帮助
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-12-18 19:45:39 | 显示全部楼层
表示编译不通过
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-12-18 20:55:32 | 显示全部楼层
黑龍 发表于 2015-12-18 19:45
表示编译不通过

我知道编译不通过 所以想让你们教教我怎么改  关于链表与文件  修改内容的:cry
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 00:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表