Re: fseek and open_memstream



On 31 Jan, 16:08, Dmitry Belous <dmitry_bel...@xxxxx> wrote:
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>
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>


.



Relevant Pages

  • Re: Can somebody help...
    ... a number of unsafe constructs and non-standard extensions. ... That value is too large to portably store in an int. ... This results in undefined behavior because you lied to printf about what ...
    (comp.lang.cpp)
  • Re: progrm to find a substring in a string
    ... Use either int mainor int main(int argc, ... char **argv). ... CBFalconer as a non-standard but more robust variant. ... This function can be replaced by the standard strstr() function. ...
    (comp.lang.c)
  • Re: static members
    ... Lem wrote: ... This header is non-standard. ... > static int dI; ... If you use <iostream>, you need to change that into: ...
    (comp.lang.cpp)
  • Re: passing a pointer to a struct to a function that uses ncurses
    ... malloc.h is non-standard, use stdlib.h. ... int mainis better. ... You have already declared data here to be of type form_data. ... already allocated space for data. ...
    (comp.lang.c)
  • Re: re online c expression to print 1-100 numbers
    ... int main ... this is tha actuall code with modifying this u have to write a online ... If this is an exercise given to you as part of a course, ... I didn't tell him to sit jobless. ...
    (comp.lang.c)