Hello all,
I want to write the following line:
mtext(1, at=Graph, text=sprintf('% 0.2f',MP$LR), line=1)
in a file (for example:Hist.R) in a function as follow:
void Graph()
{
FILE *RH=fopen("Hist .R","w");
..
..
..
fprintf(RH,"mte xt(1, at=Graph, text=sprintf('% 0.2f',MP$LR),
line=1)\n");
..
..
..
fclose(RH);
When I run the program, what program writes in the 'Hist.R' file
is:
mtext(1, at=Graph, text=sprintf('0 .00',MP$LR), line=1)
it is '0.00' instead of '%0.2f'. Can anybody help me to solve
this problem?
Thanks,
Mohsen 2 4779
Mohsen wrote:
Hello all,
I want to write the following line:
mtext(1, at=Graph, text=sprintf('% 0.2f',MP$LR), line=1)
in a file (for example:Hist.R) in a function as follow:
void Graph()
{
FILE *RH=fopen("Hist .R","w");
.
.
.
fprintf(RH,"mte xt(1, at=Graph, text=sprintf('% 0.2f',MP$LR),
line=1)\n");
.
.
.
fclose(RH);
When I run the program, what program writes in the 'Hist.R' file
is:
mtext(1, at=Graph, text=sprintf('0 .00',MP$LR), line=1)
it is '0.00' instead of '%0.2f'. Can anybody help me to solve
this problem?
1) You need to double the % character in your string above, so that it
is interpreted by fprintf correctly.
2) Consider using iostreams instead of stdio.
Nate
Mohsen wrote:
.
fprintf(RH,"mte xt(1, at=Graph, text=sprintf('% 0.2f',MP$LR),
line=1)\n");
.
When I run the program, what program writes in the 'Hist.R' file
is:
mtext(1, at=Graph, text=sprintf('0 .00',MP$LR), line=1)
it is '0.00' instead of '%0.2f'. Can anybody help me to solve
this problem?
fprintf(RH, "%s", "your stuff goes here");
or
fputs("your stuff goes here", RH);
What is currently happening is that fprintf treats your text as
a format string, so it does something with any '%' it sees. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
written.
/* Book name :
File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM
|
by: Smegly |
last post by:
Hi,
I'm confused about a situation i have ..
fprintf works in one function, but not in the other . .
This is my part of my code for the two functions ..
void customer(FILE *fin, FILE *fout, int msqid, message_buf sbuf, size_t
|
by: Andrew Fabbro |
last post by:
I have code with stuff like this all over it:
sprintf(errmsg,"somefunc(): %s has illegal character
%c",somestring,somechar);
fatal_error(errmsg);
where fatal_error() just fprintf's to stderr and exits. I'd like to
change the above to something like:
fatal_error("somefunc(): %s has illegal character
|
by: Magix |
last post by:
Hi,
I want to use fprintf to write to a file. My question about the formatted
output
How can I format so that I can allocate certain width for each %s
(Left-aignlied) ?
Example:
fprintf("%s %s %s %s, name, age, city, status);
<-------------------><----------------><----------------><------------->
|
by: G Patel |
last post by:
E. Robert Tisdale wrote:
>
> int main(int argc, char* argv) {
> quad_t m = {0, 1, 2, 3};
> int r;
> fprintf(stdout, "m = (");
> for (size_t j = 0; j < 4; ++j)
Why did you declare j as type size_t ?
| |
by: baumann |
last post by:
hi all,
i want to use the fprintf to make log.
if defined LOG_TO_FILE, it is easy to use fprintf to write the log
file.
if not defined LOG_TO_FILE, i want to simply write to error std
console.
|
by: grimrob |
last post by:
fprintf just is not working. I am using PHP Version 4.3.9. Whatever I
do fprintf just fails.
For example:
fwrite($Handle, 'A1');
fprintf($Handle, 'A2);
The first line always works, the second always fails. Likewise any
other example.
|
by: Prayag Narula |
last post by:
Hi,
I want to redefine fprintf for debugging purposes. That is I want that
all the output that is going to the stdout should be logged in a
file.
I tried something like
#define fprintf (x,y,z) my_fprintf(x,y,z)
|
by: David Mathog |
last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix
write, but no fwrite. That is, no portable C method for writing binary
data, only system calls which were OS specific. At C89 fwrite/fread
were added to the C standard to allow portable binary IO to files. I
wonder though why the choice was made to extend the unix function
write() into a standard C function rather than to extend the existing
standard C function...
|
by: vamsi |
last post by:
Hi,
I have a program, where involves creation of a thread with stack size
of 16k(minimum stack size). There is an fprintf statement in the
created thread code.
I see that there is a core dump occuring at fprintf.
code snippet :
*********************************************************************************
#include<pthread.h>
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |