473,326 Members | 2,655 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.

Question about evaluating the arguments of printf (maybe OT?)

Let us assume, f1(char *buf) and f1(char *buf) are two functions that
as a side effect calculate a string. The string will be placed in buf and
buf is returned by both f1 and f2.

Should this work:

char buf[100];
fprintf(fp,"%s%s",f1(buf),f2(buf));

Or should I take two different buffers, that is

char buf1[100],buf2[100];
fprintf(fp,"%s%s",f1(buf1),f2(buf2));
TIA,
EG
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 19 '05 #1
2 1487
Hi,

"Edith Gross" <eg******@yahoo.de> wrote in message
news:pa****************************@yahoo.de...
Let us assume, f1(char *buf) and f1(char *buf) are two functions that
as a side effect calculate a string. The string will be placed in buf and
buf is returned by both f1 and f2.

Should this work:

char buf[100];
fprintf(fp,"%s%s",f1(buf),f2(buf));
What happens is that first one function is called, it stores the string in
buf and places the return value on the stack, after that the other function
is called it overwrites the previous calculated string and places the same
return value on the stack. The printf function will be called with the
address of buf. The output will be twice the same string.
Or should I take two different buffers, that is

char buf1[100],buf2[100];
fprintf(fp,"%s%s",f1(buf1),f2(buf2));

This is the correct way.

TIA,
EG


Regards, Ron AF Greve.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Jul 19 '05 #2
Edith Gross escribió:
Should this work:

char buf[100];
fprintf(fp,"%s%s",f1(buf),f2(buf));

Or should I take two different buffers, that is

char buf1[100],buf2[100];
fprintf(fp,"%s%s",f1(buf1),f2(buf2));


You can avoid the two buffers need bt simply doing:

fprintf (fp, "%s", f1 (buf) );
fprintf (fp, "%s", f2 (buf) );

Regards.
Jul 19 '05 #3

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

Similar topics

23
by: David Frank | last post by:
How can I write a string function that encloses the input string in quotes "string" ?? below works for the "123 operation but adding " to it clobbers the "123 main() { char...
4
by: GGarramuno | last post by:
I have a program that expects its input in a specific format. Mainly, it expects floating-point values to be formatted in the form: 1.32 1. 3. 3.2345 In case you missed it, all floating...
26
by: Janice | last post by:
What is the major reason for using void*? When should we use void* for both input arguments and return value? How can we cast the void* pointer to the type we need? Thanx
14
by: Roka100 | last post by:
Hi all, I tried 2 programs : #include <stdio.h> #include <string.h> 1, int main(void){ char *str = NULL;
14
by: drM | last post by:
Hi Group, I am a little hesitant to ask this, after having read the "your question is less lively than a dead parrot answer!", but here goes. (Read thru the Faq, may have missed this, in which...
11
by: Richard Tobin | last post by:
Please excuse me if this has already been covered. Given char x; is sizeof(x)
8
by: brad2000 | last post by:
I was doing a little bit of reading in the ISO C spec. about typecasting to a void type. This caused me to have a question. In particular, I'm curious to know about section 6.3.2.2 where the specs...
29
by: Bill Cunningham | last post by:
I wrote this small program to read a 512 block of binary data and write the same to a file. My code compiled well. The only thing is when I ran the compilers binary instead of a data file of 512...
160
by: raphfrk | last post by:
Is this valid? int a; void *b; b = (void *)a; // b points to a b += 5*sizeof(*a); // b points to a a = 100;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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.