C语言操作文件

http://blog.chinaunix.net/u1/37000/showart_338364.html

 

 

// C语言读写文件.cpp : 定义控制台应用程序的入口点。
//

#include "stdio.h"
#include "string.h"

void write()
{
    FILE *fp;
    //只写打开或建立一个文本文件,只允许写数据
    fp=fopen("D:\\c.txt","wt");
    if(fp!=NULL)
    {
        char *str="C语言创建txt";
        //fputs(str,fp);
        fwrite(str,strlen(str),1,fp);
        
    }
    //fflush(fp);
    fclose(fp);
}

void read()
{
    FILE *fp;
    //只读打开一个文本文件,只允许读数据
    fp=fopen("D:\\c.txt","rt");
    if(fp!=NULL)
    {
        printf("文件大小为:%d\n",99);
    }else
    {
        printf("出错\n");
    }
    fclose(fp);
}
void main()
{
    //read();
    long size;
    FILE *fp;
    
    fp=fopen("D:\\c.txt","rb");
    fseek(fp,0,SEEK_END);
    size=ftell(fp);

    fclose(fp);
    printf("%d\n",size);

}

 

posted @ 2010-09-03 18:04  再快一点  阅读(232)  评论(0编辑  收藏  举报