Example of writing to an ASA file
Sample program CCNGAS1, shown in Figure 1, demonstrates how a program can write to an ASA file.
Figure 1. ASA
Example
/* this example shows how to write to an ASA file */
#include <stdio.h>
#define MAX_LEN 80
int main(void) {
FILE *fp;
int i;
char s[MAX_LEN+1];
fp = fopen("asa.file", "w, recfm=fba");
if (fp != NULL) {
fputs("\n\nabcdef\f\r345\n\n", fp);
fputs("\n\n9034\n", fp);
fclose(fp);
return(0);
}
fp = fopen("asa.file", "r");
for (i = 0; i < 5; i++) {
fscanf(fp, "%s", s[0]);
printf("string = %s\n",s);
}
}
The program writes five records to the file asa.file,
as follows. Note that the last record is 9034. The last single '\n'
does not create a record with a single control character (' '). If
this same file is opened for read, and the getc() function
is called to read the file 1 byte at a time, the same characters as
those that were written out by fputs() in the
first program are read.
0abcdef
1
+345
-
9034