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 4776
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning 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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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...
| |