墨愁 发表于 2015-12-18 19:23:48

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

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct friends{
       
        char name;//姓名
        char sex;   //性别
        char telephone;//电话号码
        char address;   //地址
        char wechat;    //微信
        char QQ;         //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;

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;//姓名
    char sex;   //性别
    char telephone;//电话号码
    char address;   //地址
    char wechat;    //微信
    char QQ;//QQ号码
        FILE *f;
       
        int n=0;
        struct friends *p;
        p=head;
       
        //char ch;
        //char ah;
       
        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;
}
请大神 细心一点看 这个函数是用来修改想要修改的文件内容,运用链表的方式 求大神帮助

黑龍 发表于 2015-12-18 19:45:39

表示编译不通过

墨愁 发表于 2015-12-18 20:55:32

黑龍 发表于 2015-12-18 19:45
表示编译不通过

我知道编译不通过 所以想让你们教教我怎么改关于链表与文件修改内容的:cry
页: [1]
查看完整版本: C语言问题 为什么我这个函数不行 关于链表与文件的