473,326 Members | 2,095 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,326 software developers and data experts.

fprintf

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,"mtext(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

Oct 9 '06 #1
2 4748
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,"mtext(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
Oct 9 '06 #2
Mohsen wrote:
.
fprintf(RH,"mtext(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.

Oct 10 '06 #3

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...
8
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...
3
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...
6
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...
17
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...
4
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...
4
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...
16
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...
11
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...
3
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...
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
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...
1
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: 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
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.