tk5-c90-projects/src/TXTWKR01.c

49 lines
1.1 KiB
C
Raw Normal View History

#include <stdio.h>
2026-02-08 14:59:34 +00:00
#include <errno.h>
#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_read;
FILE *fp_append;
char buffer[BUFFER_SIZE];
/* First: open for reading only to dump current content */
fp_read = fopen("dd:TESTDD", "r");
if (fp_read == NULL)
{
perror("fopen read failed");
2026-02-08 14:59:34 +00:00
printf("errno = %d\n", __errno());
return 1;
}
printf("Existing content:\n");
while (fgets(buffer, BUFFER_SIZE, fp_read) != NULL)
{
printf("%s", buffer);
}
fclose(fp_read);
/* Second: open for append only to add the new line */
fp_append = fopen("dd:TESTDD", "a");
if (fp_append == NULL)
{
perror("fopen append failed");
printf("errno = %d\n", __errno());
return 1;
}
fprintf(fp_append, "Appended from C program!\n");
fclose(fp_append);
printf("Append complete.\n");
return 0;
}