First C program

Frank Kolmann <[email protected]>
Newsgroups gmane.comp.lang.as400.c
Message-ID <CAB-SQvhkorGEeaZtisJh6dYE+ZFcTaCubYJBmDtKDUVgRAfNAw@mail.gmail.com>
Hi Jevgeni

WOW, many thanks. I have updated the program.

Proves I still dont understand pointers, especially when to use a pointer
to pointer.

I definitely did not want to use global. It was all I could get to work.



I did some more learning and I found this, here
http://www.eskimo.com/~scs/cclass/int/sx8.html

                'What are pointers to pointers good for, in practice? One
use is returning pointers from functions,

                'via pointer arguments rather than as the formal return
value.



So the answer to my confusion is , when you want to return a pointer in a
function arg,

you need a pointer to a pointer.



Frank





>*Subject: Re: First C program

> *From: Jevgeni Astanovski <Jevgeni.Astanovski@xxxxxxxxxxxxx>

> *Date: Thu, 3 Apr 2014 11:17:52 +0000

>

>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.
-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.