Sequential file of Names and Ages */
efine
CLEARSCREEN
"10331052"
efine
EOF
(-1)
efine
FILE
char
fine
FN
"AGES.TXT"
fine
FOREVER
(-1)
fine
INPUT
"I
fine
OUTPUT
"W
"
fine
MAXL
81
!ine
NEWLINE
fine
NULL
'\n' '1000'
1()
البرنامج مثال (٥)
char name[MAXL), s[MAXL);
int age:
FILE *fp;
/* file pointer */
puts (CLEARSCREEN);
fp = fopen(FN, OUTPUT);
/* open file for output */
/* Read in names & ages from keyboard & write to file */ printf("\nEnter Names and Ages; (RETURN) to quit. \n\n"); while (FOREVER) {
}
printf("\nName:
gets(name);
if (name[0] == NULL) break;
printf("Age:
gets(s);
age atoi(s);
");
putrec (name, age,fp);
/* read & convert to int *
/* write to disk */
printf("\nInput complete; closing file %s . \n", FN); fclose(fp);
/* Now read the file back and display on screen */ printf("\nReopening file %s.\n", FN);
fp = fopen(FN, INPUT);
printf("\n\nHere are the names and ages from the file. \n\n"; while (getree(name, &age, fp) != EOF) {
printf("\n%s \t%d\n", name, age);
٢٥٨
ص ٢٥٨