If you want to open a file in a function and have its pointer available in main, you must pass pointer to pointer!
Something like this:
int main()
{
_RFILE *fp ;
openfile(&fp) ;
}
void openfile(_RFILE **fp)
{
*fp = _Ropen(...) ;
}
(Bad) Alternative is to have it defined as global variable.
-----Original Message-----
From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of Frank Kolmann
Sent: Thursday, April 03, 2014 1:43 PM
To: c400-l
Subject: [C400-L] First C program
Hi
I have recoded the program based on suggestions from Barbara and Jevgeni.
I have posted the new source here.
http://wiki.midrange.com/index.php/C_version_of_DISPR
As Barbara suggested I moved the Open of the files into a function.
I had to make the file pointers GLOBAL, to get the program to work.
However if I defined the file pointers in 'main'.
I could not get the function to update the file pointers.
Any suggestions on how to define the pointers for the file OPEN.
I tried this (from compile listing) ( amongst many other attempts)
82 |int main(void)
83 |{
84 |
85 | _RFILE rpf ;
==========> .....................a................................
=INFORMATIONAL===> a - CZM0359 Automatic variable rpf contains a
86 1 | _RFILE *pf = &rpf ;
87 | _RFILE rsubf ;
==========> .....................a................................
=INFORMATIONAL===> a - CZM0359 Automatic variable rsubf contains
88 2 | _RFILE *subf = &rsubf;
89 | _RFILE rsopf ;
==========> .....................a................................
*=INFORMATIONAL===> a - CZM0359 Automatic variable rsopf contains a const member and is not initialised
90 3 | _RFILE *sopf = &rsopf;
Frank Kolmann
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/c400-l.
As an Amazon Associate we earn from qualifying purchases.