File:  [Coherent Logic Development] / freem / examples / libfreem / grades / grades.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jan 19 02:04:04 2025 UTC (2 months, 3 weeks ago) by snw
Branches: MAIN, CoherentLogicDevelopment
CVS tags: v0-63-1-rc1, v0-63-0-rc1, v0-63-0, v0-62-3, v0-62-2, v0-62-1, v0-62-0, start, HEAD
FreeM

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <freem.h>

int main(int argc, char **argv)
{
    char buf[256];
    double student_grade;
    int student_count;

    freem_ref_t *ref;

    /* initialize libfreem; use the USER namespace */
    freem_init ("USER");

    if ((ref = (freem_ref_t *) malloc (sizeof (freem_ref_t))) == NULL) {
        fprintf (stderr, "Memory allocation error.\n");

        exit (1);
    }

    ref->reftype = MREF_RT_GLOBAL;
    strcpy (ref->name, "grades");

    while (ref->subscript_count < 256) {

        ref->subscript_count = 0;

        fprintf (stdout, "Enter student name, or \"exit\" to quit:  ");
        fgets (buf, 255, stdin);

        buf[strcspn(buf, "\n")] = 0;

        if (strcmp (buf, "exit") == 0) break;

        student_count++;

        strncpy (ref->subscripts[ref->subscript_count++], buf, 254);

        fprintf (stdout, "\nEnter student grade:  ");
        fgets (buf, 255, stdin);

        buf[strcspn(buf, "\n")] = 0;

        printf("buf = '%s'\n", buf);

        strncpy (ref->value, buf, 254);

        printf("ref->value = '%s'\n", ref->value);

        freem_set (ref);

    }

    fprintf (stdout, "\nYou have entered %d student grades:\n\n", student_count);

}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>