枫's profile冷枫红舞PhotosBlogGuestbookMore Tools Help

Blog


    October 11

    不复制..直接写代码.

    #include<stdio.h>
    #include<stdlib.h>
    #include<fcntl.h>
    #include<unistd.h>
    #include<sys/types.h>
    #include<sys/stat.h>
     
    int scanf_fun();
     
    struct stu
    {
        int number;
        char name[10];
        struct stu *next;
    }
     
    int main(int argc,char *argv[])
    {
        struct stu *ps,*p1,*p2;
        int op;
        int res_read,res_wirte;
        int i;
        int num=0;
        num=scanf_fun();
        ps=creat_link(num);
        p1=p2=ps;
        if((op=open("temp.c",O_RDWR|O_TRU...,0644))==-1)
        {
            printf("open file error\n");
            //fprintf(stdout,"open file error\n");
            return -1;
            //exit(1);
        }
        res_write=write(op,p1,sizeof(struct stu));
        lseek(op,0,SEEK_SET);
        res_read=read(op,p2,sizeof(struct stu));
     
        for(i=0;i<num;i++,p2++)
        {
            //printf("res_write=%d\n",res_write);
            //printf("res_read=%d\n",res_read);
            printf("number=%d name=%s\n",p2->number,p2->name);
        }
        return 0;
    }
     
    int scanf_fun()
    {
        int n;
        printf("please input number\n");
        scanf("%d",&n);
        printf("input end\n");
    }
     
    struct stu *creat_link(int n)
    {
        struct stu *p,*head,*pi;
        int i;
        p=(struct stu *)malloc(sizeof(struct stu));
        for(i=0;i<n;i++,p++)
        {
            scanf("%d %s",&p->number,p->name);
            if(i==0)
            {
                head=pi=p;
            }
            else
            {
                p=pi->next;
                p->next=NULL;
                pi=p;
            }
        }
        return head;
    }
     
    直接写的程序,也不打算拿出去编译了...一道很简单的程序...

    Comments (2)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    枫 狄wrote:
    看看自己写能不能写出来,貌似程序肯定是有问题,不过多少的有些思路。

    问题很明显,后果很严重...比如链表节点处理得不好,没有对节点执行free()...等等~

    凑合看吧~刚起步的说...
    Oct. 12
    晔 霍wrote:
    这个我觉得复制更简单一点吧。。。
    Oct. 12

    Trackbacks

    The trackback URL for this entry is:
    http://oeardi.spaces.live.com/blog/cns!21659EF3E59E8B00!1641.trak
    Weblogs that reference this entry
    • None