diff --git a/jcl/TXTWKR01.jcl b/jcl/TXTWKR01.jcl new file mode 100644 index 0000000..f4176e0 --- /dev/null +++ b/jcl/TXTWKR01.jcl @@ -0,0 +1,7 @@ +//TXTWKR01 JOB (GCC),'File I/O Example', +// NOTIFY=@05054,CLASS=A,MSGCLASS=A, +// MSGLEVEL=(1,1),REGION=4M,TIME=1440 +//* Compile and Go Step +//STEP1 EXEC GCCCG,INFILE='@05054.SRCLIB.C(TXTWKR01)' +//GO.TESTDD DD DSN=@05054.DATA(TESTMEM),DISP=OLD +// \ No newline at end of file diff --git a/src/TXTWKR01.c b/src/TXTWKR01.c new file mode 100644 index 0000000..abd48c0 --- /dev/null +++ b/src/TXTWKR01.c @@ -0,0 +1,40 @@ +#include + +#define BUFFER_SIZE 256 + +/* Simple program to read and append to a single PDS member via DD name. */ +/* Author: Greg Gauthier */ +/* Date: 2026-02-08 */ +/* NOTE: No single-line comments due to MVS SYSIN/JCL interpretation. */ + +int main() +{ + FILE *fp; + char buffer[BUFFER_SIZE]; + + /* Open the file in update mode (read and write). */ + /* The filename is "dd:DDNAME" where DDNAME is defined in JCL. */ + fp = fopen("dd:TESTDD", "r+"); + if (fp == NULL) + { + perror("fopen failed"); + return 1; + } + + /* Read and print existing lines (to SYSOUT). */ + printf("Existing content:\n"); + while (fgets(buffer, BUFFER_SIZE, fp) != NULL) + { + printf("%s", buffer); + } + + /* After reading to EOF, the file position is at the end, so we can append. */ + fprintf(fp, "Appended from C program!\n"); + + /* Close the file. */ + fclose(fp); + + printf("Append complete.\n"); + + return 0; +} \ No newline at end of file