// Repaso de archivos: abrir, leer línea por línea, separar campos y cerrar.
#include <stdio.h>

#define PATH_SIZE 128
#define LINE_SIZE 64
#define NAME_SIZE 20

int remove_newline(char s[]) {
    for (int i = 0; s[i] != '\0'; i++) {
        if (s[i] == '\n') {
            s[i] = '\0';
            return 1;
        }
    }
    return 0;
}

int main(void) {
    char path[PATH_SIZE];
    if (fgets(path, PATH_SIZE, stdin) == NULL) {
        fprintf(stderr, "Falta el nombre del archivo\n");
        return 1;
    }
    remove_newline(path);

    FILE *file = fopen(path, "r");
    if (file == NULL) {
        perror(path);
        return 1;
    }

    char line[LINE_SIZE];
    int number = 0;
    int total = 0;
    while (fgets(line, LINE_SIZE, file) != NULL) {
        number++;
        char name[NAME_SIZE];
        int people;
        char extra[2];
        int fields = sscanf(line, "%19s %d %1s", name, &people, extra);
        if (fields == 2) {
            total = total + people;
        } else {
            fprintf(stderr, "Línea %d: mal formada, se omite\n", number);
        }
    }
    fclose(file);
    printf("Personas: %d\n", total);
    return 0;
}
