Annotation of freem/examples/libfreem/grades/grades.c, revision 1.1
1.1 ! snw 1: #include <stdio.h>
! 2: #include <string.h>
! 3: #include <stdlib.h>
! 4:
! 5: #include <freem.h>
! 6:
! 7: int main(int argc, char **argv)
! 8: {
! 9: char buf[256];
! 10: double student_grade;
! 11: int student_count;
! 12:
! 13: freem_ref_t *ref;
! 14:
! 15: /* initialize libfreem; use the USER namespace */
! 16: freem_init ("USER");
! 17:
! 18: if ((ref = (freem_ref_t *) malloc (sizeof (freem_ref_t))) == NULL) {
! 19: fprintf (stderr, "Memory allocation error.\n");
! 20:
! 21: exit (1);
! 22: }
! 23:
! 24: ref->reftype = MREF_RT_GLOBAL;
! 25: strcpy (ref->name, "grades");
! 26:
! 27: while (ref->subscript_count < 256) {
! 28:
! 29: ref->subscript_count = 0;
! 30:
! 31: fprintf (stdout, "Enter student name, or \"exit\" to quit: ");
! 32: fgets (buf, 255, stdin);
! 33:
! 34: buf[strcspn(buf, "\n")] = 0;
! 35:
! 36: if (strcmp (buf, "exit") == 0) break;
! 37:
! 38: student_count++;
! 39:
! 40: strncpy (ref->subscripts[ref->subscript_count++], buf, 254);
! 41:
! 42: fprintf (stdout, "\nEnter student grade: ");
! 43: fgets (buf, 255, stdin);
! 44:
! 45: buf[strcspn(buf, "\n")] = 0;
! 46:
! 47: printf("buf = '%s'\n", buf);
! 48:
! 49: strncpy (ref->value, buf, 254);
! 50:
! 51: printf("ref->value = '%s'\n", ref->value);
! 52:
! 53: freem_set (ref);
! 54:
! 55: }
! 56:
! 57: fprintf (stdout, "\nYou have entered %d student grades:\n\n", student_count);
! 58:
! 59: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>