473,659 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fprintf works in one function but not in the other .

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
buf_length, int timer)
----------------------------------------------------------------------------
-----
//printf("%s\n", buff);
time(&now);
fprintf(fout,"--------------------------------------------------\n");
fprintf(fout,"C ustomer %s: %s\rArrival time: %s\r", custRef,
custAction, ctime(&now));

//fprintf(fout,"--------------------------------------------------\n");

----------------------------------------------------------------------------
------

this fprintf works. . .

now this is part of the other function teller()

void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td, int Tw)
----------------------------------------------------------------------------
-----

printf("Custome r statistics for Teller %d\n", getpid());
printf("Servici ng customer %s - Action required %s\n", custNum,
custAct);
fprintf(fout, "Customer statistics for Teller %d\n",getpid()) ;

----------------------------------------------------------------------------
----

this fprintf does not work . .
Does anyone know why this would be the case ?

Matt

Nov 14 '05 #1
8 1986
Smegly wrote:

fprintf(fout, "Customer statistics for Teller %d\n",getpid()) ;

this fprintf does not work . .
In what sense does it "not work?" It doesn't compile? It causes your
program to crash? It prints something you didn't expect?
Does anyone know why this would be the case ?


I can't compile the teller function, because message_buf is an
unrecognized type, and custNum, custAct, and fout haven't been declared
in the scope of the teller function. Is this the same problem you're
experiencing? If not, you need to take out whatever isn't necessary,
and add whatever is necessary, to show us your problem.

--
Russell Hanneken
rg********@pobo x.com
Remove the 'g' from my address to send me mail.
Nov 14 '05 #2

"Smegly" <sm****@eftel.n et.au> wrote in message news:40******** @usenet.per.par adox.net.au...
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
buf_length, int timer)
----------------------------------------------------------------------------
-----
//printf("%s\n", buff);
time(&now);
fprintf(fout,"--------------------------------------------------\n");
fprintf(fout,"C ustomer %s: %s\rArrival time: %s\r", custRef,
custAction, ctime(&now));


I think the carriage return character, '\r', is your culprit.
Try changing it to the newline character, '\n'.
[..]
Nov 14 '05 #3
Vijay Kumar R Zanvar wrote:
"Smegly" <sm****@eftel.n et.au> wrote in message news:40******** @usenet.per.par adox.net.au...

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
buf_length, int timer)
----------------------------------------------------------------------------
-----
//printf("%s\n", buff);
time(&now);
fprintf(fout,"--------------------------------------------------\n");
fprintf(fout,"C ustomer %s: %s\rArrival time: %s\r", custRef,
custAction, ctime(&now));

I think the carriage return character, '\r', is your culprit.
Try changing it to the newline character, '\n'.


You snipped the line where he says "this fprintf works." He says the
problem is with the second fprintf statement in his post, which is in
another function.

--
Russell Hanneken
rg********@pobo x.com
Remove the 'g' from my address to send me mail.
Nov 14 '05 #4
In the second function you do fprintf(fout, ...) ;
Where is fout defined, in the first function it is clearly defined but I
can't see it defined in the second one?
Good Luck!
The Fat Man
"Smegly" <sm****@eftel.n et.au> wrote in message
news:40******** @usenet.per.par adox.net.au...
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
buf_length, int timer)
-------------------------------------------------------------------------- -- -----
//printf("%s\n", buff);
time(&now);
fprintf(fout,"--------------------------------------------------\n"); fprintf(fout,"C ustomer %s: %s\rArrival time: %s\r", custRef,
custAction, ctime(&now));

//fprintf(fout,"--------------------------------------------------\n");

-------------------------------------------------------------------------- -- ------

this fprintf works. . .

now this is part of the other function teller()

void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td, int Tw) -------------------------------------------------------------------------- -- -----

printf("Custome r statistics for Teller %d\n", getpid());
printf("Servici ng customer %s - Action required %s\n", custNum,
custAct);
fprintf(fout, "Customer statistics for Teller %d\n",getpid()) ;

-------------------------------------------------------------------------- -- ----

this fprintf does not work . .
Does anyone know why this would be the case ?

Matt

Nov 14 '05 #5
sorry i corrected the code in the editor ..

The void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td, int
Tw)

is actually FILE *fout, etc ... )

the statement does not add any thing to the simulation_log file.

Matt
"Matthew Jakeman" <m.*******@nosp am.lancaster.ac .uk> wrote in message
news:c8******** **@alliance.lan cs.ac.uk...
In the second function you do fprintf(fout, ...) ;
Where is fout defined, in the first function it is clearly defined but I
can't see it defined in the second one?
Good Luck!
The Fat Man
"Smegly" <sm****@eftel.n et.au> wrote in message
news:40******** @usenet.per.par adox.net.au...
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 buf_length, int timer)


--------------------------------------------------------------------------
--
-----
//printf("%s\n", buff);
time(&now);

fprintf(fout,"--------------------------------------------------\n");
fprintf(fout,"C ustomer %s: %s\rArrival time: %s\r", custRef,
custAction, ctime(&now));

//fprintf(fout,"--------------------------------------------------\n");


--------------------------------------------------------------------------
--
------

this fprintf works. . .

now this is part of the other function teller()

void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td, int

Tw)

--------------------------------------------------------------------------
--
-----

printf("Custome r statistics for Teller %d\n", getpid());
printf("Servici ng customer %s - Action required %s\n", custNum,
custAct);
fprintf(fout, "Customer statistics for Teller %d\n",getpid()) ;


--------------------------------------------------------------------------
--
----

this fprintf does not work . .
Does anyone know why this would be the case ?

Matt


Nov 14 '05 #6
Smegly wrote:
sorry i corrected the code in the editor ..

The void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td, int
Tw)

is actually FILE *fout, etc ... )

the statement does not add any thing to the simulation_log file.

Matt


Seems like you had a global variable by name - fout .
See, now you have got a valid reason why you should try to avoid global
variables as far as possible.

--
Karthik.
Humans please 'removeme_' for my real email.
Nov 14 '05 #7
>
The void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td, int Tw)

is actually FILE *fout, etc ... )

the statement does not add any thing to the simulation_log file.

Matt

Test the return value of fprintf (yes you can do that), I expect it to
return an error then check errno. Most likely the file handle fout is
invalid. Also make sure getpid() has its prototype included.

Nov 14 '05 #8
In <A2************ ********@wagner .videotron.net> "Mario Charest" <po********@127 .0.0.1> writes:

The void teller(FILE *fptr1, message_buf rbuf, int msqid, int i, int Td,

int
Tw)

is actually FILE *fout, etc ... )

the statement does not add any thing to the simulation_log file.

Matt

Test the return value of fprintf (yes you can do that), I expect it to
return an error then check errno. Most likely the file handle fout is
invalid.


Then, the fprintf call invokes undefined behaviour and all the bets are
off.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #9

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

Similar topics

1
2195
by: Arne Claus | last post by:
Hi. I've got a strange problem here with PHP5 (5.0.4). I've got file A, defining a class A and a file B, which sets up an Object of A (aObj) in the global scope like this. ----- A.php ---- class A { //... }
3
1395
by: Art X | last post by:
The reason for this has do to with the nature of WebTV and will be directed to WebTV users with a conditional so that it will have no effect on PC users. I'm trying to create a function that will put focus to a form element (with a short delay) when the division that it is in is changed from hidden to visible. For a one time use, this works:
7
9597
by: Melissa | last post by:
I'm trying to create a function that I can put in a query field that will consecutively number the records returned by the query starting at 1 and will start at 1 each time the query is run. So far I have the function shown below which doesn't work. If Reset is True then all I get is 1 in every field and if Reset is False, the numbering does not start at 1 each time the query is run. Can someone show me a function that works. Function...
3
1533
by: Norm via DotNetMonster.com | last post by:
I have an onchange event which fires when the content of an HTML textbox changes. My problem is that when I try to compare the content of this textbox with another HTML textbox using an if statement, I get a Page Error and my code fails. This has got to be a no brainer. Any help out there for a clueless newbie? This works: function ow8t_onchange() { alert("success");
2
2523
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I am really desperate now, because I havent' been able to locate the origin of the problem for a couple of days now.. PROBLEM: the message digest obtained differs each time I execute the code, but works perfectly when applying the "control", that...
12
2280
by: manochavishal | last post by:
Hi, I am having strange problem in my Program. I cannot paste the whole program as it is huge so just pasting the lines i think are necessary. I am passing a integer array pointer to a function. **********
5
1376
by: Andrew Poulos | last post by:
I tested the JSON parse/to code from json.org and it works but I don't understand how. Could someone explain how something in this format works: (function() {...})(); Andrew Poulos
0
1002
by: origenes | last post by:
Hi, I have this function that works... function _getNoCategories($parent){ $sql = 'SELECT id FROM mod_catalogue_category WHERE parent='.$parent; $cats = $this->db->get_results($sql); foreach($cats as $cat) { //$r.=$cat->id.','; $this->excludeCat.=$cat->id.',';
16
6681
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)
0
8339
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,...
0
8851
Oralloy
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...
1
8535
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,...
0
8629
tracyyun
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...
0
7360
agi2029
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...
1
6181
isladogs
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...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
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
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.