int main(void) { double average; Employee workers[SIZE]; if (!(fp = fopen("payfile.txt", "r"))) { printf("payfile.txt could not be opened for input."); exit(1); } if (!(csis = fopen("csis.txt", "w"))) { printf("csis.txt could not be opened for output."); exit(1); } getEmployees(workers); showEmployees(workers); males(workers); highestFemale(workers); lowestMale(workers); average = averageSalary(workers); femalesUnderAverage(workers, average); maleRatio(workers, average); superEmployee(workers); setRaise(workers); fclose(fp); fclose(csis); return 0; }
/* Main function. */ int main(int argc, char *argv[]) { /* Local variables. */ char option = 'x'; int exitValue; char *fileName; FILE *employeeFile; employee *employees; float total = 0; // Validation: Number of arguments from console. if (argc != 2) { printf("Error: Numero de parametros invalido.\nDebe iniciar asi: ./taller.out <archivo.csv>\n"); exit(0); } fileName = argv[1]; employeeFile = fopen(fileName, "r"); if(employeeFile == NULL) { printf("No se pudo abrir el archivo\n"); exit(0); } numEmployees = getNumEmployees(employeeFile); if (numEmployees <= 0) { printf("Error: No hay trabajadores en el archivo\n"); exit(0); } printf("Hay %d trabajadores en el archivo\n", numEmployees); employees = (employee *)malloc(sizeof(employee) * numEmployees); do { getOption(&option); switch (option) { case 'a': registerEmployees(employees, employeeFile); break; case 'b': showEmployees(employees); break; case 'c': total = getTotal(employees); printf("TOTAL: %.2f", total); break; case 'q': printf("Saliendo del programa...\n"); break; default: printf("La opcion '%c' no es valida. Volviendo al menu.\n", option); break; } } while(option != 'q'); exitValue = fclose(employeeFile); if(exitValue == 0) { printf("se cerro el archivo\n"); } /* Free memory. */ free(employees); return 0; }