/*
    第2種情報処理技術者試験    平成7年度・春期・午後 問11 プログラム1
                                BohYoh Shibata PREPARATION
*/

#include <stdio.h>
#include <string.h>
#define MATCH     1
#define UNMATCH   0
#define KEY1 "年賀"

typedef struct{
    char name[16],relt[8],mode[4][4],tel[16],zip[8],addr[32];
} ADR;

int mdchk( char*, ADR* );

main()
{
    FILE *fp;
    ADR   rbuf;
    char  obuf[33];
    int   count;

    count = 0;
    fp = fopen( "jusho.txt" , "r" );
    while ( fgets( (char*)&rbuf , sizeof(ADR) ,fp ) != NULL ) {
        memset( obuf,' ',sizeof(obuf) );
        obuf[sizeof(obuf)-1] = '\0';
        if ( mdchk( KEY1,&rbuf ) == MATCH ) {
            count++;
            strncpy( obuf    , rbuf.name , sizeof(rbuf.name) );
            strncpy( obuf+16 , rbuf.tel  , sizeof(rbuf.tel) );
            printf( "    %s\n" , obuf );
        } 
    }
    fclose( fp );
    printf( "\n*** 条件に合致した人数 = %d名\n",count );
}

int mdchk( char *str , ADR *jrec )
{
    int  id;

    for ( id=0 ; id<4 ; id++)
        if (strncmp(jrec->mode[id],str,sizeof(jrec->mode[id])) == 0)
            return MATCH;
    return UNMATCH;
}