fseek和open_memstream [英] fseek and open_memstream

查看:81
本文介绍了fseek和open_memstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当我取消注释fseek line buf变空?

#define _GNU_SOURCE

#include< stdio.h>


int main(){

char * buf = 0;

int size = 0;

FILE * f = open_memstream(& buf,& size);

fwrite(" test",1,4,f);

// fseek(f,0,SEEK_SET);

fclose(f);

fprintf(stderr,buf);

}

-

德米特里

Why when I uncomment fseek line buf become empty?
#define _GNU_SOURCE
#include <stdio.h>

int main() {
char *buf = 0;
int size = 0;
FILE* f = open_memstream(&buf, &size);
fwrite("test", 1, 4, f);
// fseek(f, 0, SEEK_SET);
fclose(f);
fprintf(stderr, buf);
}
--
Dmitry

推荐答案

Dmitry Belous< dm *********** @ ua.fmwrote:
Dmitry Belous <dm***********@ua.fmwrote:

为什么当我取消注释fseek行buf变空?

#define _GNU_SOURCE

#include< stdio.h>


int main(){

char * buf = 0;

int size = 0;

FILE * f = open_memstream(& buf,& size);

fwrite(" test",1,4,f);

// fseek( f,0,SEEK_SET);

fclose(f);

fpr intf(stderr,buf);

}
Why when I uncomment fseek line buf become empty?
#define _GNU_SOURCE
#include <stdio.h>

int main() {
char *buf = 0;
int size = 0;
FILE* f = open_memstream(&buf, &size);
fwrite("test", 1, 4, f);
// fseek(f, 0, SEEK_SET);
fclose(f);
fprintf(stderr, buf);
}



open_memstream()不是ISO C函数。它或它的返回值,

可能以一种清除buf的方式与fseek()交互,但_why_这个

发生在这里是偏离主题的。如果它是POSIX函数(我不知道,你的

编译器应该告诉你),请在comp.unix.programmer中询问。如果不是,

找到一个处理你的实现的新闻组 - 从

的外观来看,那是'gcc,所以问问gnu.help。某事。


Richard

open_memstream() is not an ISO C function. It, or its return value,
probably interacts with fseek() in a way that clears buf, but _why_ this
happens is off-topic here. If it''s a POSIX function (I don''t know, your
compiler should tell you), ask in comp.unix.programmer. If it''s not,
find a newsgroup that deals with your implementation - from the looks of
it, that''s gcc, so ask gnu.help.something.

Richard


文章< ep *********** @ pandora.alkar .net>,

Dmitry Belous< dm *********** @ ua.fmwrote:
In article <ep***********@pandora.alkar.net>,
Dmitry Belous <dm***********@ua.fmwrote:

> ;为什么当我取消注释fseek行buf变空?
>Why when I uncomment fseek line buf become empty?


> #define _GNU_SOURCE
#include< stdio.h>
>#define _GNU_SOURCE
#include <stdio.h>


> int main(){

char * buf = 0;

int size = 0;

FILE * f = open_memstream(& buf,& size);
>int main() {
char *buf = 0;
int size = 0;
FILE* f = open_memstream(&buf, &size);



什么是open_memstream()?它不是C89的一部分,我从来没有听说它是C99的一部分。

What is open_memstream() ? It is not part of C89, and I''ve never
heard of it being part of C99.


fwrite(" test" ;,1,4,f);
// fseek(f,0,SEEK_SET);

fclose(f);

fprintf(stderr,buf ); $
}
fwrite("test", 1, 4, f);
// fseek(f, 0, SEEK_SET);
fclose(f);
fprintf(stderr, buf);
}



您似乎正在使用实现库函数。你需要在一个专门从事实施的地方询问。

-

重要的是要记住,当它来到法律,电脑

永远不会复制,只有人类复制。计算机给出了

命令,而非许可。只有人才能获得许可。

- Brad Templeton

You appear to be using an implementation library function. You
will need to ask in a location that specializes in your implementation.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton


1月31日16:08,Dmitry Belous< dmitry_bel。 .. @ ua.fmwrote:
On 31 Jan, 16:08, Dmitry Belous <dmitry_bel...@ua.fmwrote:

为什么当我取消注释fseek行buf变空?

#define _GNU_SOURCE

#include< stdio.h>


int main(){

char * buf = 0;

int size = 0;

FILE * f = open_memstream(& buf,& size);

fwrite(" test",1,4,f);

// fseek(f,0,SEEK_SET);

fclose(f);

fprintf(stderr,buf);}
Why when I uncomment fseek line buf become empty?
#define _GNU_SOURCE
#include <stdio.h>

int main() {
char *buf = 0;
int size = 0;
FILE* f = open_memstream(&buf, &size);
fwrite("test", 1, 4, f);
// fseek(f, 0, SEEK_SET);
fclose(f);
fprintf(stderr, buf);}



< Off-topic>

非标准的open_memstream()函数,来自在线手册页

I '已经查看过,允许你将一个字符缓冲区视为一个输出

你可以写的流。


回到开头可能被认为是作为准备

令状再次,所以实际上它清除了缓冲区。


有关更多信息,我建议您使用GNU库新闻组或

邮件列表。

< / Off-topic>

<Off-topic>
The non-standard open_memstream() function, from the online man pages
I''ve viewed, allows you to treat a character buffer as an output
stream to which you can write.

Seeking back to the beginning is presumably regarded as preparation to
write again, so in effect it clears the buffer.

For more information, I suggest you use a GNU libraries newsgroup or
mailing list.
</Off-topic>


这篇关于fseek和open_memstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆