int query1() { int maxano, minano, npublics, nomes; char filename[40]; char *linha; maxano = minano = npublics = nomes = 0; printf("Ficheiro para leitura: "); if (fgets(filename, 40, stdin) != NULL) { linha = newline(filename); reset_index(); reset_stats(); reset_lista(); reset_length(); reset_catalogo(); if (parser_file(linha) == 0) { printf("Erro na abertura do ficheiro(Talvez ficheiro não exista ou tenha outro nome?)\n"); } else { maxano = getMaxAno(); minano = getMinAno(); npublics = getNPublics(); nomes = getNomes(); printf("Ficheiro lido: %s\n", linha); printf("Nº publicacoes: %d\n", npublics); printf("Anos: [%d a %d]\n", minano, maxano); printf("Nº de nomes lidos: %d\n", nomes); } } else { printf("Erro na abertura do ficheiro"); } return 1; }
void main(void) { unsigned char cal_length, cal_dia; unsigned int length, dia, dia_offset, latest_l, latest_d; unsigned int tot_acc, mass_acc, timb_acc; unsigned int tot_num, mass_num, timb_num; unsigned int count1, count2, count3; OSCCON = 255; OSCTUNEbits.PLLEN = 1; TRISA = 0b00011111; PORTA = 0; ADCON1 = 0b00001101; TRISB = 0; PORTB = 0; TRISC = 0b00010000; PORTC = 0b00000000; TRISD = 0; PORTD = 0; TRISE = 0; PORTE = 0; init_display(); init_counters(); LED1 = 0; LED2 = 0; LED3 = 0; latest_l = 0; latest_d = 0; tot_acc = 0; tot_num = 0; timb_acc = 0; timb_num = 0; mass_acc = 0; mass_num = 0; cal_length = read_ad(0); cal_dia = read_ad(1); dia_offset = 2; while (1) { length = read_length(cal_length); dia = dia_offset + read_diameter(cal_dia); write_length(length); write_dia(dia); if (!CALIBRATE) { count1 = read_counter(1); count2 = read_counter(2); count3 = read_counter(3); cal_length = read_ad(0); cal_dia = read_ad(1); write_debug_info(cal_length, cal_dia, count1, count2, count3); } if (!RESET_DIA) { reset_dia(); } if (!RESET_LENGTH) { delay(20000); delay(20000); if (!RESET_LENGTH) { LED1 = 1; if (length >= 100) { tot_num = tot_num + 1; tot_acc = tot_acc + length / 100; latest_l = length; latest_d = dia; if (dia >= 15) { timb_num = timb_num + 1; timb_acc = timb_acc + length / 100; } else { mass_num = mass_num + 1; mass_acc = mass_acc + length / 100; } } reset_length(); while (!RESET_LENGTH) { write_length(0); write_dia(0); write_length(8); write_dia(8); } write_stats(latest_l, latest_d, tot_num, tot_acc, timb_num, timb_acc, mass_num, mass_acc); LED1 = 0; } } } }