Skip to content

Instantly share code, notes, and snippets.

@MarceloPincheira
Created July 4, 2017 07:42
Show Gist options
  • Save MarceloPincheira/454534550e56231ed83b25cbe9c73f42 to your computer and use it in GitHub Desktop.
Save MarceloPincheira/454534550e56231ed83b25cbe9c73f42 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv){
char rut[9];
int votantes, lista, listaA, listaB, nulos;
int i;
lista = 0;
listaA = 0;
listaB = 0;
nulos = 0;
votantes = 0;
FILE *archivo;
archivo = fopen ( "LISTA", "r" );
//INICIO LECTURA ARCHIVO
if (archivo==NULL) {
printf("¡Error! el archivo no fue abierto\n");
}else{
printf("ARHCIVO ABIERTO CORRECTAMENTE\n");
rewind(archivo);
while(feof(archivo) == 0){
fscanf(archivo, "%d", &votantes);
if((votantes > 0) && (votantes < 20)){
printf("CANTIDAD VOTANTES: %d\n", votantes);
if(votantes == 20){
printf("Se completo el numero de votantes por hoy\n");
}
listaA = listaB = nulos = 0;
for(i=0; i<votantes; i++){
fscanf(archivo, "%s %d", rut, &lista);
printf("RUT %s LISTA %d\n", rut, lista);
if(lista == 1){
listaA++;
}else if(lista == 2){
listaB++;
}else{
nulos++;
}
}
printf("LISTA A %d LISTA B %d NULOS %d\n", listaA, listaB, nulos);
}else if(votantes == 0){
printf("No se registraron votantes\n");
}
else if(votantes > 20){
printf("Se superó el número de votantes por día\n");
}
}
}
fclose ( archivo );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment