473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Writing to memory instead of FILE

(Using MS VC++ 6.0)

In a lib file I have a method that takes a FILE as parameter. The
method writes some text to this file. I don't need the text in a file
but in a variable.
So how can I make the method write to a buffer insted of a file on a
disk?

Thanks,
Anders Thomsen
Jul 22 '05 #1
6 1649

"Anders Thomsen" <ju**@mexp.dk> wrote in message
news:5d**************************@posting.google.c om...
(Using MS VC++ 6.0)

In a lib file I have a method that takes a FILE as parameter. The
method writes some text to this file. I don't need the text in a file
but in a variable.
So how can I make the method write to a buffer insted of a file on a
disk?

Thanks,
Anders Thomsen


You cannot. If you can switch to using C++ I/O where this is REALLY EASY,
instead of using FILE, where it is COMPLETELY IMPOSSIBLE.

john
Jul 22 '05 #2
John Harrison wrote:
[snip]
You cannot. If you can switch to using C++ I/O where this is REALLY EASY,
instead of using FILE, where it is COMPLETELY IMPOSSIBLE.


That is a qualified "COMPLETELY IMPOSSIBLE", meaning that within the confines
of proper and portable C++, it isn't possible.

However, there may be ways to accomplish what you desire using operating-system
specific file i/o hooks and/or other hacking & subterfuge -- BUT, these should
only be considered as a last resort, and only by someone that fully understands
the implementation details, implications, and ramifications of such hacking.
Something else that could be considered is how the library is linked in -- if
it is a library in the traditional sense (static link), the OP may be able to
provide specialized implementations of the standard file i/o functions (say,
fputs) and they redirect the output to memory. Depending on how your compiler
performs and resolves the link, this may or may not work. Again, an advanced
(hack) method that has all sorts of caveats.
Jul 22 '05 #3
> You cannot. If you can switch to using C++ I/O where this is REALLY EASY,
instead of using FILE, where it is COMPLETELY IMPOSSIBLE.


I don't have access to the source of the lib file, so I'm afraid
that's not possible.

Thanks for the info.
Jul 22 '05 #4
"Anders Thomsen" <ju**@mexp.dk> wrote in message
news:5d**************************@posting.google.c om...
(Using MS VC++ 6.0)

In a lib file I have a method that takes a FILE as parameter. The
method writes some text to this file. I don't need the text in a file
but in a variable.
So how can I make the method write to a buffer insted of a file on a
disk?


With the caveat that this isn't portable (or standard), you could open both ends
of a pipe or a socket, associate one ebd with a FILE * that you pass to your
library, and populate the variable yourself by reading from the other end. As
convoluted as this is, it would still be much faster than file I/O and it
wouldn't require having write access to the disk.

Claudio Puviani
Jul 22 '05 #5
On 29 Apr 2004 06:56:45 -0700, ju**@mexp.dk (Anders Thomsen) wrote:
(Using MS VC++ 6.0)

In a lib file I have a method that takes a FILE as parameter. The
method writes some text to this file. I don't need the text in a file
but in a variable.
So how can I make the method write to a buffer insted of a file on a
disk?


How about opening the FILE in "a+" mode, and using ftell and fseek?

Jul 22 '05 #6

"Walter Tross" <wa****@waltertross.com> wrote in message
news:54********************************@4ax.com...
On 29 Apr 2004 06:56:45 -0700, ju**@mexp.dk (Anders Thomsen) wrote:
(Using MS VC++ 6.0)

In a lib file I have a method that takes a FILE as parameter. The
method writes some text to this file. I don't need the text in a file
but in a variable.
So how can I make the method write to a buffer insted of a file on a
disk?


How about opening the FILE in "a+" mode, and using ftell and fseek?


How would that help? Its still a file.

john
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
17
by: Manlio Perillo | last post by:
Regards. On my system: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32, Windows XP I have this problem: >>> n = 61409 + 1 >>> data = 'x' * n
7
by: W. Jordan | last post by:
Hello, I am using Response.WriteFile (filename) to write a file that on the server to my web client. I discover that the while a client request a big file, for example, a 14m-bytes one, the...
12
by: romayankin | last post by:
I plan to write site on a few language. For this reason I'm trying to find the most convenient way to output strings depending on their unique ID. As far as I plan to have pretty much strings...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
6
by: Shawn | last post by:
Hello: I have the following code in a PHP file. An HTML form passes user comment data to the PHP, which then appends the user comments to the end of the HTML file on which the form is located....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.