break read and append into two operations
Some checks failed
MVS Delete Members / delete-members (push) Failing after 14s
MVS Submit & Execute / upload-and-run (push) Failing after 50s

This commit is contained in:
Greg Gauthier 2026-02-08 15:16:29 +00:00
parent 78ea32b3d9
commit 5742a21d59
2 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,5 @@
//TXTWKR01 JOB (GCC),'File I/O Example',
// NOTIFY=@05054,CLASS=A,MSGCLASS=A,
// NOTIFY=@05054,CLASS=A,MSGCLASS=H,
// MSGLEVEL=(1,1),REGION=4M,TIME=1440
//* Compile and Go Step
//STEP1 EXEC GCCCG,INFILE='@05054.SRCLIB.C(TXTWKR01)'

View File

@ -10,35 +10,39 @@
int main()
{
FILE *fp;
FILE *fp_read;
FILE *fp_append;
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", "a+");
if (fp == NULL)
/* First: open for reading only to dump current content */
fp_read = fopen("dd:TESTDD", "r");
if (fp_read == NULL)
{
perror("fopen failed.");
perror("fopen read failed");
printf("errno = %d\n", __errno());
return 1;
}
/* Read and print existing lines (to SYSOUT). */
printf("Existing content:\n");
while (fgets(buffer, BUFFER_SIZE, fp) != NULL)
while (fgets(buffer, BUFFER_SIZE, fp_read) != NULL)
{
printf("%s", buffer);
}
fclose(fp_read);
/* After reading to EOF, the file position is at the end, so we can append. */
fprintf(fp, "Appended from C program!\n");
/* 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;
}
/* Close the file. */
fclose(fp);
fprintf(fp_append, "Appended from C program!\n");
fclose(fp_append);
printf("Append complete.\n");
return 0;
}