C语言 文件操作

/**

*@author cody

*@date 2014-08-09

*@description copy text file

* FILE *fopen(filename,openmode)

* fclose(FILE *stream)

* int fseek(stream,offset,whence)

* long ftell(stream)

* void rewind(stream)

*/



#include <stdio.h>

#include <stdlib.h>

#include <string.h>



int main(int argc, char const *argv[])

{

    

    FILE *fp = fopen("file","r+");

    if(fp == NULL){



        perror("open error");

        exit(1);

    }



    /*if(fseek(fp,8,SEEK_SET) != 0){

        perror("seek error");

        exit(0);

    }



    long pos = ftell(fp);

    printf("file current pos = %ld\n",pos );



    fputc('W',fp);*/

    fseek(fp,4,SEEK_SET);

    fputs("Hello,my name is cody wu\nwhat's your name\n",fp);



    

    

    fclose(fp);





    return 0;

}

 

你可能感兴趣的:(文件操作)