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("d ata.out",'w+");
mpz_out_str(out put,10,mpz_data ); /* Outputs mpz_data in base 10) */
rewind(output);
fgets(output,bu ffer,40);
Buffer would contain the human readable value contained in mpz_data.
Thanks,
Walter 8 5916
<wa************ ***@gmail.com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.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("d ata.out",'w+"); mpz_out_str(out put,10,mpz_data ); /* Outputs mpz_data in base 10) */ rewind(output); fgets(output,bu ffer,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
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
<wa************ ***@gmail.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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 misunderstandin g?
RP
Rod Pemberton wrote: <wa************ ***@gmail.com> wrote in message news:11******** **************@ e56g2000cwe.goo glegroups.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 misunderstandin g?
RP
I think you still are [misunderstandin g].
I can call mpz_out_str(std out, 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(out file, 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_st r(stdout, 10, value));
Walter wa************* **@gmail.com escreveu: Rod Pemberton wrote:
[snipped] I think you still are [misunderstandin g].
I can call mpz_out_str(std out, 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(out file, 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_st r(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
I guess I should read to documentation more...
Thanks,
Walter 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_Keit h) 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. 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.c om, 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/googlegroupsrep ly/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 to stdout/stderr,
I'd like it to write to stdout, to a file, and/or call a logging
function.
So my output function might look something like this:
OutputFacility& OutputFacility::put(const std::string& s) {
cout << s; // print to stdout
|
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
would like to redirect/intercept the output of transCore class to this GUI
class. I wrote a sample program that demonstrate how I did it, but I am not
sure if it's any good. Can anyone critic my code? If there's any
non-standard conforming code or...
|
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 should depend on user input (command line arguments
actually). If the user decides he/she wants verbose output, I will pass
std::cout as the last argument when calling foo(). But what should I pass if
the user doesn't want any output? And how...
|
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 console as well as to file, my code is as
below,
=======================================================================
#include <iostream.h>
#include<ostream>
#include<sstream>
|
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 think
the relevant portions of the standard are:
| |
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.
|
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 this program returns. I'm just missing the stepshere. I know that I can set the Shell command to an integer,but this only returns a 0 to me telling me that it executed, notwhat is being returned to the console by that application. Isthere a way to...
|
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 which invites will target selected personnel among our customers via email. Each email will provide a custom hyperlink for each respondent using a SQL generated GUID value in the querystring. The GUID will be checked for validity before the user...
|
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 null character
in the middle of the output. I think it was a null character, Firefox
displays it as a '?' and the W3C validator says it's a non-sgml
character '0'. I changed the code around a bit and now the only
problem is that it (on some pages of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |