Example program to access ram disk – Rockwell Automation 1771-DMC_DMC1_DMC4_DXPS Control Coprocessor User Manual User Manual
Page 59
![background image](/manuals/579606/59/background.png)
Chapter 4
Using the Programming Environment
4-7
Example Program to Access RAM Disk
Refer to the following C program (CAT.C) as an example of accessing
the control-coprocessor RAM disk. Note the use of standard C library
functions—e.g.,
fopen()
,
getc()
, and
fclose()
—to access RAM-
disk files.
You create the file, compile it, and send it to OS-9 as a binary file.
Then, you run the C program on OS-9.
/***** cat.c ::: copy from files to standard out *****
*
* This program is used as an example so you can learn to use the
* Standard Library functions for processing characters from an
* input file and writing characters on the standard output,
* and so you can use a command in a “pipeline” with redirection
* modifiers (’<’ and ’>’). Try doing a:
*
* cat file1 file2 file3 > outfile
*
* type of operation to see how “cat” can merge files...
*
* “What goes around, comes around.”
*/
/* First, includes and defines... */
#include
#include
/* then the function and parameter declarations... */
main ( argc, argv )
int argc;
char **argv;
/* then the body of executable function statements... */
{
/* private variable declarations */
FILE *infil; /* file to copy to standard output */
int c, /* character (or EOF) gotten from input file */
i; /* which command line argument is being processed */
/*
* This command has no option switches. It simply copies the
* input file(s) character by character to standard output.
* If only the command itself is specified, it does nothing.
* Probably better tell the user such...!
*/
if ( argc == 1 ) /* no file names on command line */
{
fprintf ( stderr, “No files on command line. Exiting.\n” );
exit ( 0 );
}