标题:为什么这个东西写不进文件啊 新手才学文件 谢谢指教了
只看楼主
GUnever
Rank: 2
等 级:论坛游民
帖 子:59
专家分:25
注 册:2012-3-3
结帖率:95.24%
 问题点数:0 回复次数:0 
为什么这个东西写不进文件啊 新手才学文件 谢谢指教了
Linklist*insert(Linklist*head)
{
    FILE *fp;
    Linklist*p1,*p2,*p3;            /*p3进行创建一个新的节点*/
    int k,n,flag,num,age,salary;
    char tele[12],name[10],sex,xueli[10];
    system("cls");
    if((fp=fopen("d:\z.txt","w"))==NULL)
    {
        printf("open error");
        exit(1);
    }
    printf("             Welcome to the adding system\n How many workers do you wanna add in?\n");
    p1=p2=head;
    p1=p1->next;
    scanf("%d",&n);
    for(k=0;k<n;k++)
    {
        printf("\nPlease give the new information:\n num: ");
        scanf("%d",&num);
        for(;;p2=p2->next,p1=p1->next)            /*这里的是标致是否找到了链表合适的位置进行插入*/
        {
            
            if(num<p1->num&&num>p2->num)           /***********找到了刚好在中间的位置***********/   
            {
                flag=1;
                break;
            }
            if(p1==NULL)         /***********并没有找到中间的位置 输入的编号直接按照大小直接放在最后面***********/   
            {
                flag=2;
                break;
            }
            if(num==p2->num||num==p2->num)                         /**********这里是输入了相同的编号 指针初始化 要求重新输入 在进行插入*********/
            {
                printf("the num has been register,Please input another one:");
                scanf("%d",&num);
                p1=p2=head;
                p1=p1->next;
            }
        }
        p3=(Linklist*)malloc(len);            /*********存入插入的节点数据**********/
        p3->num=num;
        
        printf("name:");
        scanf("%s",name);
        strcpy(p3->name,name);
        
        printf("\nage:");
        scanf("%d",&age);
        p3->age=age;
        getchar();
        
        printf("\nsex:");
        scanf("%c",&sex);
        p3->sex=sex;
        
        printf("\ntele:");
        scanf("%s",tele);
        strcpy("p3->tele.tele");
        
        printf("\nxueli:");
        scanf("%s",xueli);
        strcpy(p3->xueli,xueli);
        
        printf("\nsalary:");
        scanf("%d",&salary);
        p3->salary=salary;
        if(flag==1)                   /**********中间位置插入*********/
        {
            p2->next=p3;
            p3->next=p1;
        }
        if(flag==2)              /*********末尾插入**********/
        {
            p2->next=p3;
            p3->next=NULL;
        }
        p1=p2=head;
        p1=p1->next;
    }
    for(p1=head;p1!=NULL;p1=p1->next)
    {
        if(fwrite(p1,sizeof(Linklist),1,fp)!=1);
        printf("eqweq");
        exit(1);
    }   
        return head;
}
每次最后fwrite就自动退出了 写不进去 不知道为什么啊 帮下我把
搜索更多相关主题的帖子: head system Welcome 东西 insert 
2012-04-14 16:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-365782-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.978102 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved