FILE *p 是什么类型的指针呢?

SHOUYU2 2010-12-09 09:26:53
FILE *fpt = fopen("a.txt","r");
为什么不能puts(fpt);将a.txt里面的内容打印出来?
只能通过fscanf转换一下
...全文
806 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnlm2 2010-12-29
  • 打赏
  • 举报
回复
首先要打开一个文件啊,你也可以自己写一个那样的函数!
hai040 2010-12-29
  • 打赏
  • 举报
回复
你自己可以写个这样的函数
没有估计是因为不常用又容易用其它函数实现
zr0519 2010-12-29
  • 打赏
  • 举报
回复
没有那么高级啊
flyerwing 2010-12-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 t1397018 的回复:]
FILE是一个结构体指针,里面包括文件名啊,文件缓冲区啊什么的,你研究下标准库你就可以通过FILE结构得到文件里的内容了
CCoder
[/Quote]
大虾说的对呀.
Mapleliang 2010-12-29
  • 打赏
  • 举报
回复
文件指针,不过,我记得它只指向文件头吧
zy020118 2010-12-10
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 luciferisnotsatan 的回复:]
引用 10 楼 luciferisnotsatan 的回复:

有个函数叫 fputs
int fputs(
const char *str,
FILE *stream
);

看错lz的意思了

你要答应出来的话,只能先读到内存,然后再输出的屏幕。

文件和屏幕,键盘一样。属于输入输出流
你这么写,类似于键盘放在屏幕上,你不按键盘,屏幕上也没东西。
[/Quote]

+1

两个流之间不能直接通信吧~~~它们间的数据交换要程序控制
luciferisnotsatan 2010-12-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 luciferisnotsatan 的回复:]

有个函数叫 fputs
int fputs(
const char *str,
FILE *stream
);
[/Quote]
看错lz的意思了

你要答应出来的话,只能先读到内存,然后再输出的屏幕。

文件和屏幕,键盘一样。属于输入输出流
你这么写,类似于键盘放在屏幕上,你不按键盘,屏幕上也没东西。
jngd 2010-12-10
  • 打赏
  • 举报
回复
for linux
总而言之、言而总之,不管是win还是linux,FILE *里面存放的都是open打开的原始fd和一些文件信息,譬如当前文件偏移、文件大小、读写状态等等。。。。
///////////////////////

//from stdio.h
typedef struct _IO_FILE FILE;

//from libio.h
struct _IO_FILE {
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
#define _IO_file_flags _flags

/* The following pointers correspond to the C++ streambuf protocol. */
/* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
char* _IO_read_ptr; /* Current read pointer */
char* _IO_read_end; /* End of get area. */
char* _IO_read_base; /* Start of putback+get area. */
char* _IO_write_base; /* Start of put area. */
char* _IO_write_ptr; /* Current put pointer. */
char* _IO_write_end; /* End of put area. */
char* _IO_buf_base; /* Start of reserve area. */
char* _IO_buf_end; /* End of reserve area. */
/* The following fields are used to support backing up and undo. */
char *_IO_save_base; /* Pointer to start of non-current get area. */
char *_IO_backup_base; /* Pointer to first valid character of backup area */
char *_IO_save_end; /* Pointer to end of non-current get area. */

struct _IO_marker *_markers;

struct _IO_FILE *_chain;

int _fileno;
#if 0
int _blksize;
#else
int _flags2;
#endif
_IO_off_t _old_offset; /* This used to be _offset but it's too small. */

#define __HAVE_COLUMN /* temporary */
/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];

/* char* _save_gptr; char* _save_egptr; */

_IO_lock_t *_lock;
#ifdef _IO_USE_OLD_IO_FILE
};


[Quote=引用 9 楼 wizard_tiger 的回复:]
FILE是一个在stdio.h中预先定义的一个文件类型。
要先声名一个文件指针变量然后用文件函数操作。
在书上看到过一个FILE类型
typedef struct{
short level;/*缓冲区“满/空”的程度*/
unsigned flags;/*文件状态标志字*/
char fd;
unsigned char hold;
short bsize;/*缓……
[/Quote]
luciferisnotsatan 2010-12-10
  • 打赏
  • 举报
回复
有个函数叫 fputs
int fputs(
const char *str,
FILE *stream
);
wizard_tiger 2010-12-10
  • 打赏
  • 举报
回复
FILE是一个在stdio.h中预先定义的一个文件类型。
要先声名一个文件指针变量然后用文件函数操作。
在书上看到过一个FILE类型
typedef struct{
short level;/*缓冲区“满/空”的程度*/
unsigned flags;/*文件状态标志字*/
char fd;
unsigned char hold;
short bsize;/*缓冲区大小*/
unsigned char *buffer;/*数据缓冲区的位置*/
unsigned char *curp;/*当前读写位置指针*/
unsigned istemp;
short token;
}FILE;
aimerjing 2010-12-10
  • 打赏
  • 举报
回复
我只知道是文件指针,还不太会用
龙哥依旧 2010-12-10
  • 打赏
  • 举报
回复
struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
};
typedef struct _iobuf FILE;
t1397018 2010-12-09
  • 打赏
  • 举报
回复
FILE是一个结构体指针,里面包括文件名啊,文件缓冲区啊什么的,你研究下标准库你就可以通过FILE结构得到文件里的内容了










CCoder
李迟 2010-12-09
  • 打赏
  • 举报
回复
楼主的想法不错啊,只是不能实现,这个比较麻烦了。
就想叫yoko 2010-12-09
  • 打赏
  • 举报
回复
楼主说得有道理,这样真麻烦
hukui161 2010-12-09
  • 打赏
  • 举报
回复
FILE翻译出来不就叫文件。
無_1024 2010-12-09
  • 打赏
  • 举报
回复
文件指针
只能用文件的读写操作函数
liutengfeigo 2010-12-09
  • 打赏
  • 举报
回复
文件指针。
liutengfeigo 2010-12-09
  • 打赏
  • 举报
回复
是呀....
搞得你怎么纠结。

33,323

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧