Re: First C program
Barbara Morris <[email protected]>
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <[email protected]> |
On 2014-04-03 06:42, Frank Kolmann wrote:
> 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.
Rather than make the file pointers global, you could have the function
just handle one file at a time, with the filename and open-mode as
parameters, and returning the file pointer.
pf = fOpenFile (PFILENAME, "rr");
...
static _RFILE *fOpenFile(const char *filename,
const char *openmode,
int rc)
{
_RFILE *f;
f = _Ropen(filename, openmode);
if (f EQ NULL)
{
printf("can't open file %s\n", PFILENAME);
exit(rc);
}
return f;
}
Be careful to code "static" for any function that you want to be local
to the module. I would not use GLOBAL for this, since that would be very
confusing, even though it would work.
--
Barbara
--
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.