473,385 Members | 1,185 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,385 software developers and data experts.

Output stream data to a string

I am writing a program, using the gmp library. I need to take the
output (mpz_out_str) and put it back into a string. Is there an easy
way to take stream output, and 'place it' into a string?

I can do it with fopen, mpz_out_str, rewind, fgets.

Is there a better way such as using pipe or fdopen, dup etc?

Basically, I want (headers, variable declarations, error checking
excluded)

output=fopen("data.out",'w+");
mpz_out_str(output,10,mpz_data); /* Outputs mpz_data in base 10) */
rewind(output);
fgets(output,buffer,40);

Buffer would contain the human readable value contained in mpz_data.

Thanks,

Walter

May 1 '06 #1
8 5894

<wa***************@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
I am writing a program, using the gmp library. I need to take the
output (mpz_out_str) and put it back into a string. Is there an easy
way to take stream output, and 'place it' into a string?

I can do it with fopen, mpz_out_str, rewind, fgets.

Is there a better way such as using pipe or fdopen, dup etc?

Basically, I want (headers, variable declarations, error checking
excluded)

output=fopen("data.out",'w+");
mpz_out_str(output,10,mpz_data); /* Outputs mpz_data in base 10) */
rewind(output);
fgets(output,buffer,40);

Buffer would contain the human readable value contained in mpz_data.


Is there a reason you can't use sprintf()? You didn't say what format
mpz_data is in.

string:
sprintf(buffer, "%s", mpz_data)

unsigned long:
sprintf(buffer, "%08lx", mpz_data)
Rod Pemberton
May 1 '06 #2
the call to mpz_out_str is

size_t mpz_out_str (FILE *stream, int base, mpz_t op)

where op is the gmp integer data type (binary)

What I am asking is for a way to implement sprintf for stream output.

Thanks,

Walter

May 1 '06 #3

<wa***************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
the call to mpz_out_str is

size_t mpz_out_str (FILE *stream, int base, mpz_t op)

where op is the gmp integer data type (binary)

What I am asking is for a way to implement sprintf for stream output.

Thanks,


Isn't that called fprintf()? Or am I still misunderstanding?

RP
May 1 '06 #4

Rod Pemberton wrote:
<wa***************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
the call to mpz_out_str is

size_t mpz_out_str (FILE *stream, int base, mpz_t op)

where op is the gmp integer data type (binary)

What I am asking is for a way to implement sprintf for stream output.

Thanks,


Isn't that called fprintf()? Or am I still misunderstanding?

RP


I think you still are [misunderstanding].

I can call mpz_out_str(stdout, 10, value) where value contains gmp's
representation of an number, (for my example, 31415926535) and on
stdout, i get
31415926535

If I call mpz_out_str(outfile, 10, value) and outfile has been fopen'ed
with the file name "gmp.out") I get
31415926535 in the file gmp.out.

I want to be able to feed the output of mpz_out_str back into a
character array.

If mpz_out_str returned a char *, I could do

sprintf(buffer,"%s",mpz_out_str(stdout, 10, value));

Walter

May 2 '06 #5
wa***************@gmail.com escreveu:
Rod Pemberton wrote: [snipped]

I think you still are [misunderstanding].

I can call mpz_out_str(stdout, 10, value) where value contains gmp's
representation of an number, (for my example, 31415926535) and on
stdout, i get
31415926535

If I call mpz_out_str(outfile, 10, value) and outfile has been fopen'ed
with the file name "gmp.out") I get
31415926535 in the file gmp.out.

I want to be able to feed the output of mpz_out_str back into a
character array.

If mpz_out_str returned a char *, I could do

sprintf(buffer,"%s",mpz_out_str(stdout, 10, value));

Walter,

This is technically OT in this NG, however, it seems what you want is to
use the gmp library function gmp_sprintf or even better (see manual why)
gmp_snprintf.

HTH

--
Cesar Rabak

May 2 '06 #6
I guess I should read to documentation more...

Thanks,

Walter

May 2 '06 #7
wa***************@gmail.com writes:
I am writing a program, using the gmp library. I need to take the
output (mpz_out_str) and put it back into a string. Is there an easy
way to take stream output, and 'place it' into a string?

I can do it with fopen, mpz_out_str, rewind, fgets.

[...]

This is really a question about what functionality is provided by gmp,
not about the C programming language.

Probably gnu.utils.help would be a good place to ask this question.
Or you could spend a few minutes with the gmp documentation. (Note
that converting something to a string isn't really "output", so the
information might not be where you're looking for it.

<OT>mpz_get_str</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 2 '06 #8
wa***************@gmail.com wrote:

I guess I should read to documentation more...


Probably. You should also learn to include context to avoid
creating such a meaningless article. See below.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
May 2 '06 #9

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

Similar topics

12
by: Matt Garman | last post by:
I'd like to create a "custom output facility". In other words, I want an object whose use is similar to std::cout/std::cerr, but offers more flexibility. Instead of simply writing the parameter...
2
by: Jason | last post by:
Hello, I have a class, transCore, that does certain work, and by default, prints its progress to the stand output. Later, I will to write a GUI class that encapsulate the transCore class. I...
6
by: William Payne | last post by:
Hi, I have a function declared as: void foo(const std::string& s, std::ostream& verbose_output); I want foo() to write a lot of data to the ostream if it's a valid stream. If it's valid or not...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
3
by: Fernando Arbeiza | last post by:
Hi: I need some clarification about a code like this: printf("%s", "a string with NO trailing newline"); scanf("%d", &i); Regarding if a fflush() of the standard output is needed or not. I...
8
by: FS Liu | last post by:
Hi, I am writing ATL Service application (XML Web service) in VS.NET C++. Are there any sample programs that accept XML as input and XML as output in the web service? Thank you very much.
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
8
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for...
2
by: Mike P2 | last post by:
I made a Stream-inheriting class that just removes the tabs (actually the 4 spaces VS prefers to use) from the beginning of lines and empty lines. At first I was having trouble with it adding a...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.