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', //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 // MSGLEVEL=(1,1),REGION=4M,TIME=1440
//* Compile and Go Step //* Compile and Go Step
//STEP1 EXEC GCCCG,INFILE='@05054.SRCLIB.C(TXTWKR01)' //STEP1 EXEC GCCCG,INFILE='@05054.SRCLIB.C(TXTWKR01)'

View File

@ -10,35 +10,39 @@
int main() int main()
{ {
FILE *fp; FILE *fp_read;
FILE *fp_append;
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
/* Open the file in update mode (read and write). */ /* First: open for reading only to dump current content */
/* The filename is "dd:DDNAME" where DDNAME is defined in JCL. */ fp_read = fopen("dd:TESTDD", "r");
fp = fopen("dd:TESTDD", "a+"); if (fp_read == NULL)
if (fp == NULL)
{ {
perror("fopen failed."); perror("fopen read failed");
printf("errno = %d\n", __errno()); printf("errno = %d\n", __errno());
return 1; return 1;
} }
/* Read and print existing lines (to SYSOUT). */
printf("Existing content:\n"); printf("Existing content:\n");
while (fgets(buffer, BUFFER_SIZE, fp) != NULL) while (fgets(buffer, BUFFER_SIZE, fp_read) != NULL)
{ {
printf("%s", buffer); printf("%s", buffer);
} }
fclose(fp_read);
/* After reading to EOF, the file position is at the end, so we can append. */ /* Second: open for append only to add the new line */
fprintf(fp, "Appended from C program!\n"); fp_append = fopen("dd:TESTDD", "a");
if (fp_append == NULL)
{
perror("fopen append failed");
printf("errno = %d\n", __errno());
return 1;
}
/* Close the file. */ fprintf(fp_append, "Appended from C program!\n");
fclose(fp); fclose(fp_append);
printf("Append complete.\n"); printf("Append complete.\n");
return 0; return 0;
} }