码迷,mamicode.com
首页 > 其他好文 > 详细

file 文件操作

时间:2016-03-10 01:49:29      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:file文件操作

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int fun()
{
int ch;
int ret=0;
while(isdigit(ch=getchar()))
 {
 ret=ret*10+ch-48;
 }
 ungetc(ch,stdin);
return ret;
}
 
void fun1()
{
int ch;
int ret=fun();
printf("%d\n",ret);
ch=getchar();
putchar(ch);
}
void fun2()
{
 
FILE *fp=fopen("1.txt","r");
char ch=fgetc(fp); printf("%c\n",ch);
    ch=fgetc(fp);   printf("%c\n",ch);
fseek(fp,-2,SEEK_CUR);//当前
ch=fgetc(fp);
printf("%c\n",ch);
fseek(fp,-5,SEEK_END);//末尾 
//rename("1.txt","22.txt"); //改文件名为22.txt 需要带后缀的全名
fclose(fp);
//rename("1.txt","22.txt"); 关闭文件或者不关闭文件均可以实现改名字 
 printf("%c\n",ch);
 
       
}
 
void main()
{
fun1();
#if(1)
fun2();
#endif
}


file 文件操作

标签:file文件操作

原文地址:http://sts609.blog.51cto.com/11227442/1749370

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!