コード例 #1
0
ファイル: sort_word.c プロジェクト: descent/jmcce
int main()
{
  FILE *cinfile ;
  char buf[MAX_BUF_LEN] ;

  cinfile = fopen(PHONE_CIN_FILE, "r") ;
  if( !cinfile ) {
    printf("Error opening the file %s\n", PHONE_CIN_FILE) ;
    return 1 ;
  }

  do {
    fgets(buf, MAX_BUF_LEN, cinfile) ;
  } while( strncmp(buf, CHARDEF_BEGIN, strlen(CHARDEF_BEGIN)) ) ;

  for(;;) {
    fgets(buf, MAX_BUF_LEN, cinfile) ;
    if(buf[0] == '%') break ;
    if( DoWord(buf) == DO_WORD_ERROR) {
      printf("%s file error!\n", PHONE_CIN_FILE) ;
      return 1 ;
    }
  }
  fclose(cinfile) ;

  if( strncmp( buf, CHARDEF_END, strlen(CHARDEF_END))) {
    printf("The end of the file %s is error!\n", PHONE_CIN_FILE) ;
    return 1 ;
  }

  CountSort() ;
  Output() ;

  return 0 ;
}
コード例 #2
0
ファイル: sort_word.c プロジェクト: Seachaos/libchewing
int main(int argc, char* argv[])
{
	FILE *cinfile;
	char buf[ MAX_BUF_LEN ];
	char *phone_cin;

	if (argc < 2) {
		fprintf( stderr, "Usage: sort_word <phone.cin>\n" );
		return 1;
	}

	phone_cin = argv[1];
	cinfile = fopen( phone_cin, "r" );
	if ( ! cinfile ) {
		fprintf( stderr, "Error opening the file %s\n", phone_cin );
		return 1;
	}

	do {
		fgets( buf, MAX_BUF_LEN, cinfile );
	} while ( strncmp( buf, CHARDEF_BEGIN, strlen( CHARDEF_BEGIN ) ) );

	for ( ; ; ) {
		fgets( buf, MAX_BUF_LEN, cinfile );
		if ( buf[ 0 ] == '%' )
			break;
		if ( DoWord( buf ) == DO_WORD_ERROR ) {
			fprintf( stderr, "The file %s is corrupted!\n", phone_cin );
			return 1;
		}
	}
	fclose( cinfile );

	if ( strncmp( buf, CHARDEF_END, strlen( CHARDEF_END ) ) ) {
		fprintf( stderr, "The end of the file %s is error!\n", phone_cin );
		return 1;
	}

	CountSort();
	Output();

	return 0;
}