Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.1 kB
3
Indexable
Never
///Liberías*******************************************************************************************************************************
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <string.h>

///Constantes*****************************************************************************************************************************
# define MAX_CHAR 50
# define MAX_PERS 10

///Estructuras****************************************************************************************************************************
typedef struct {
    char name_M[MAX_CHAR];
    char genderM;
    int ageM;
}Moons;


typedef struct {
    char name_DS[MAX_CHAR];
    char genderDS;
    int ageDS;
}DemonSlayers;



typedef struct {
    DemonSlayers demonslayers[MAX_PERS];
    Moons moons[MAX_PERS];
    int demons;
    int humans;
}Kimetsu_Characters;

///Funciones******************************************************************************************************************************
// D|daki|D|muzan|D|akaza|H|tanjiro|H|mitsuri|H|zenitsu|D|nezuko

///MAIN___________________________________________________________________________________________________________________________________
int main(){
    Kimetsu_Characters personaje;

    personaje.demons = 0;
    personaje.humans = 0;

    char input[100];
    int lenght = 0;
    int i = 0, j = 0;

    printf ("Input: ");
    fgets (input, 100, stdin);
    input [ strlen( input ) - 1 ] = '\0';

    lenght = strlen (input);

    printf ("Your INPUT is: %s", input);
    printf ("\nYour INPUT has %d characters.\n", lenght);

    while ( input[i] != '\0' ) {

        if(input[i] == 'D') {
            //Es un demonio
            personaje.demons++;
            i++;
            i++;

            j = 0;
            while (input[i] != '|' && input[i] != '\0') {
                personaje.demonslayers[personaje.demons-1].name_DS[j] = input[i];
                j++;
                i++;
            }
            personaje.demonslayers[personaje.demons-1].name_DS[j] = '\0';
            if(input[i] != '\0') {
                i++;
            }

        } else {
            if(input[i] == 'H') {
                //Es un humano
                personaje.humans++;
                i++;
                i++;

                j = 0;
                while (input[i] != '|' && input[i] != '\0') {
                    personaje.moons[personaje.humans-1].name_M[j] = input[i];
                    j++;
                    i++;
                }
                personaje.moons[personaje.humans-1].name_M[j] = '\0';
                if(input[i] != '\0') {
                    i++;
                }

            }
        }

    }

    printf("Total of demons: %d\n", personaje.demons);
    for(i = 0; i < personaje.demons; i++) {
        printf("\tDEMON %d: %s\n", i+1, personaje.demonslayers[i].name_DS);
    }

    printf("Total of humans: %d\n", personaje.humans);
    for(i = 0; i < personaje.humans; i++) {
        printf("\tHUMAN %d: %s\n", i+1, personaje.moons[i].name_M);
    }

    return 0;

}