把握命运,追逐梦想

对自己所做的事要有兴趣,同时还要能够坚持不懈

统计

留言簿(1)

阅读排行榜

评论排行榜

一个文件操作的例子

#include<string.h>
#include
<stdio.h>
int main()
{
    FILE 
*pFile;
    pFile 
= fopen("myfile.txt","w+");

    
char str[8= "qwertyu";
    fwrite(str,
1,7,pFile);

    
long pos = ftell(pFile);

    
char ch = getc(pFile);

    
int ret = 0;

    ret 
= printf("%d",pos);
    ret 
= printf("%c",ch);

    ret 
= fseek(pFile,-5,2);

    
if(ret != 0)
    
{
        printf(
"wrong");
    }

     
    pos 
= ftell(pFile);
    
    ch 
=getc(pFile);
    ret 
= printf("%d",pos);
    ret 
= printf("%c",ch);

    
char strbuf[6];
    
//rewind(pFile);
    ret = fread(strbuf,1,3,pFile);

    printf(
"%s",strbuf);

    fclose(pFile);
    
return 0;

}

posted on 2009-07-29 15:45 把握命运 阅读(132) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理