just trying to read a goddamned file
This commit is contained in:
parent
c30bdcebc9
commit
e14f9f9db0
@ -1,6 +1,5 @@
|
||||
//TXTWKR01 JOB (JCC),'JCC File I/O Test',
|
||||
// NOTIFY=@05054,CLASS=A,MSGCLASS=H,
|
||||
//TXTWKR01 JOB (GCC),'File I/O Test',NOTIFY=@05054,CLASS=A,MSGCLASS=H,
|
||||
// MSGLEVEL=(1,1),REGION=4M,TIME=1440
|
||||
//STEP1 EXEC JCCCLG,INFILE='@05054.SRCLIB.C(TXTWKR01)'
|
||||
//STEP1 EXEC GCCCG,INFILE='@05054.SRCLIB.C(TXTWKR01)'
|
||||
//GO.TESTDD DD DSN=@05054.DATA(TESTMEM),DISP=SHR,
|
||||
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0,DSORG=PS)
|
||||
|
||||
@ -1,26 +1,46 @@
|
||||
#include <stdio>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
#define MAX_LINES 100
|
||||
#define LINE_LEN 256
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf((char *)"Program starting - about to fopen(dd:TESTDD, \"r\")\n");
|
||||
|
||||
FILE *fp;
|
||||
char buf[256];
|
||||
char lines[MAX_LINES][LINE_LEN];
|
||||
int count = 0;
|
||||
char buf[LINE_LEN];
|
||||
|
||||
/* === Read phase === */
|
||||
fp = fopen("dd:TESTDD", "r");
|
||||
if (fp == NULL) {
|
||||
printf((char *)"fopen returned NULL\n");
|
||||
printf((char *)"fopen read failed\n");
|
||||
fputs("Cannot open for read\n", stdout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf((char *)"fopen succeeded!\n");
|
||||
printf((char *)"Existing content:\n");
|
||||
while (fgets(buf, 256, fp) != NULL) {
|
||||
printf((char *)"%s", buf);
|
||||
fputs("Existing content:\n", stdout);
|
||||
while (fgets(buf, LINE_LEN, fp) && count < MAX_LINES) {
|
||||
fputs(buf, stdout); /* echo to JES */
|
||||
strncpy(lines[count], buf, LINE_LEN-1);
|
||||
lines[count][LINE_LEN-1] = '\0';
|
||||
count++;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
printf((char *)"Read complete.\n");
|
||||
/* === Write phase (rewrite everything + append) === */
|
||||
fp = fopen("dd:TESTDD", "w");
|
||||
if (fp == NULL) {
|
||||
fputs("Cannot open for write\n", stdout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
fputs(lines[i], fp);
|
||||
}
|
||||
fputs("Appended from C program!\n", fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
fputs("Append complete (via rewrite).\n", stdout);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user