FILE pointer from buffer

Started by
4 comments, last by Mihail121 20 years, 9 months ago
Ok guys a hard one .Let''s say i have somekind of buffer.I want to get FILE pointer that points to that buffer.Just like that:


unsigned char *buff;

//Fill buff with stuff


FILE *f;

//Connect f with the buffer


How can i do this if it''s possible?10x "You losers better learn...NOONE CONTROLS OUR GOD DAMN LIFE!!!" - MANOWAR
Advertisement
quote:Original post by Mihail121
"You losers better learn...NOONE CONTROLS OUR GOD DAMN LIFE!!!" - MANOWAR

"The Goods made Heavy Metal"


"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
quote:Original post by Estor
quote:Original post by Mihail121
"You losers better learn...NOONE CONTROLS OUR GOD DAMN LIFE!!!" - MANOWAR

"The Goods made Heavy Metal"

Silly Me it is "Return of the WarLord" !

[edited by - Estor on July 3, 2003 9:57:39 AM]
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
FILE pointers don''t work that way. If you use C++, you can use stream IO on char buffers just as you can on files, but in C it''s not possible. That said, it wouldn''t be difficult to create some fread/fwrite style functions that would work on a char pointer instead of a FILE pointer.

Kippesoep
I don''t know of any way to do it, other than to write it to a new file then open that file for reading.

I don''t understand the purpose of doing such. What function, that operates on a FILE*, do you need to use on your character stream? For example, if you were doing something like fread, the same functionality can be done on your buffer using memcpy. For fscanf, you can use sscanf on your buffer. There''s an equivalent operation for anything you could do with the file routines.
Hey Estor glad to see other fans of ManOwaR here.Long live metal and death to the false metals.

Cgoat,observe the following situation.A file system returns a content buffer of a file(byte *buff = load_file("shit.jpg")).In order to load a JPEG file with the JPEG lib you have to pass a file pointer(i.e. FILE *f).So i need to construct a FILE pointer from the file buffer.Anyway the problem is solved and i wanna thank everyone for the replies.Glad there are still people that doesn''t flame here .


"You losers better learn...NOONE CONTROLS OUR GOD DAMN LIFE!!!" - MANOWAR

This topic is closed to new replies.

Advertisement