× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



A couple of suggestions:
- use C++ instead of C and use static object.
The constructor for the static object will run when activation group is 
created and destructor will run when activation group is destroyed.
- another approach is to use Register Activation Group Exit Procedure 
(CEE4RAGE) API. The registered exit procedure will be called when 
activation group is destroyed.

    Alexei
always speaking only for myself

"We have all reasons to assume that our assumptions are not unreasonable."



"Boris" <bbresc512@xxxxxxxxxx> 
Sent by: c400-l-bounces+pytel=us.ibm.com@xxxxxxxxxxxx
05/29/2006 06:02 PM
Please respond to
C programming iSeries / AS400 <c400-l@xxxxxxxxxxxx>


To
<c400-l@xxxxxxxxxxxx>
cc

Subject
[C400-L] Reading file basics






Hi all
I'm trying to write a function that opens a file, does some checking and 
returns to the main program. The problem is that the function is located 
in 
a separate module and the main program is unaware of the file at all. All 
it's interested in is the result of the function. So it can't pass the 
file 
as a parameter. On the other hand I don't want the function to open and 
close the file on every call. For example, here is my code in the 
function:

_RIOFB_T *fb;
 _RFILE *infile;
if ( (infile = _Ropen("FILENAME", "rr")) == NULL ) {
  print_err("Can't open FILENAME file\n");
  return 0;
}
....
// some code here
....
_Rclose(infile);
return 1;

The first solution that came to my mind is to declare infile "static" and 
only open it once. It actually works, but then I don't know when to close 
the file, which is probably okay because the file will be closed when the 
main program finishes. I guess it's just not the correct programming.
It's actually a very small function, so I would want to create global 
variables and handle it with 2 more functions (one for open and another 
for 
close).
Are there any other ways?

Thanks in advance. 


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.