Пример #1
0
static void modify_rating( struct Ordered_container* lib_ID )
{
    struct Record* rec;
    int ID, rating;
    
    /* read input and check for errors */
    if ( !read_int( &ID ) || !read_int( &rating ) )
        return;

    rec = get_data_ptr( lib_ID, comp_Record_to_ID, &ID );
    
    if ( rec )
    {
        /* make sure rating is in range */
        if ( rating < MIN_RATING || rating > MAX_RATING )
        {
            print_error( "Rating is out of range!\n" );
            return;
        }
        
        printf( "Rating for record %d changed to %d\n", get_Record_ID(rec), rating );
        set_Record_rating( rec, rating );
    }
    else
    {
        print_error( "No record with that ID!\n" );
    }
}
Пример #2
0
struct Record* load_Record(FILE* infile)
{
    int record_id, rating;
    char medium[RECORD_MEDIUM_SIZE];
    char title[RECORD_TITLE_SIZE];
    struct Record *new_record;
    char fmt_str[30];
    sprintf(fmt_str, "%%d %%%ds %%d", RECORD_MEDIUM_SIZE-1);
    if (fscanf(infile, fmt_str, &record_id, medium, &rating) != 3)
        return NULL;
    fgetc(infile); /* read the leading space */
    if (!fgets(title, RECORD_TITLE_SIZE, infile)) {
        return NULL;
    }
    title[strlen(title)-1] = '\0'; /* remove the newline character */
    new_record = create_Record(medium, title);
    set_Record_rating(new_record, rating);
    new_record->ID = record_id;
    id_number_counter--;
    /* set id_number counter to the largest record_id read in */
    if (record_id > id_number_counter)
        id_number_counter = record_id;
    return new_record;
}