Home > Software design >  My program doesn't load my functions from my personal lib
My program doesn't load my functions from my personal lib

Time:06-30

I am a technology management student and I fell in love with the C Language. I also enjoy interpretation games and decided to develop a small C program with a small dungeon embedded in it.

I made the codes and when left in a single file, they worked, but I decided to divide them into multiple files and create libraries for the classes, but the program does not advance now.

I will put the codes below.

The main code in file main.c:

#include <stdio.h>
#include "selector.h"
#include "classes.h"

//Bloco principal de execucao / Main execution block
int main() {
    startMenu();
    return 0;
}

int startMenu() {
    int selection;
    selection = 0;
    printf("Hello Adventurer! Welcome to C Single Dungeon\n");
    do {
        printf("Type 1 for Portuguese, 2 for English: \n");
        scanf("%d", &selection);
        if (selection == 1) {
            extern auxSelection(selection);
        } else if (selection == 2) {
            extern auxSelection(selection);
        } else {
            printf("Digite uma opcao valida! /  Choose a valid option!\n\n");
            system("PAUSE");
            system("CLS");
        }

    } while(selection > 2 || selection < 1);
}

The Selector Header in file selector.c

#include "selector.h"
#include <stdlib.h>

//call to auxiliar function
int auxSelection(int selection);

//call to Pt_BR language
int lang_PtBR();

//Call to En_US language
int lang_EnUS();

The lib selector.h:

#ifdef SELECTOR_H
#define SELECTOR_H
#include "classes.h"
//Funcao Auxiliar de Selecao / Acessory Selector
int auxSelection(int selection){
    if (selection == 1){
        lang_PtBR();
    } else{
        lang_EnUS();
    }
    return 0;
}


//Funcao de Selecao em Portugues
int lang_PtBR() {
    int tmp_class = 0;
    int confirmClass = 0;
    do {
        printf("Seja bem vindo ao C Single Dungeon!\n");
        printf("Escolha sua Classe:\n");
        printf("1 - Guerreiro\n2 - Mago\n");
        scanf("%d", &tmp_class);
        if (tmp_class == 1) {
            printf("Guerreiros sao letais no combate corpo a corpo. Como guerreiro voce recebe os seguintes bonus:\n 2 de ataque\n 1 de defesa\n-1 de esquiva\n-2 de defesa magica\n");
            printf("Deseja mesmo ser um guerreiro?\n1 - SIM\n2 - Preciso pensar melhor...\n");
            scanf("%d", &confirmClass);
            if (confirmClass == 1) {
                extern int warriorPtBR();
            } else {
                confirmClass = 0;
                tmp_class = 0;
            }
        } else if (tmp_class == 2) {
            printf("Magos sao mestres no uso das forcas sobrenaturais. Como mago voce recebe os seguintes:\n 2 de ataque magico\n-1 de defesa\n 1 de esquiva\n");
            printf("Deseja mesmo ser um mago?\n1 - SIM\n2 - Preciso pensar melhor...");
            scanf(%d, &confirmClass);
            if (confirmClass == 1) {
                extern int magePtBR();
            } else {
                confirmClass = 0;
                tmp_class = 0;
            }
        } else {
            printf("Eu, seu narrador, sou um velho cansado, tenho dificuldade em entender algumas coisas, por favor, selecione uma das duas respostas que lhe pedi.\n");
            system("PAUSE");
            system("CLS");
            extern void lang_PtBR();
        }

    } while (tmp_class > 2 || tmp_class < 1);
    return 0;
}

//English Selection Function
int lang_EnUS() {
    int tmp_class = 0;
    int confirmClass = 0;
    do {
        printf("Welcome to C Single Dungeon!\n");
        printf("Choose your class:\n");
        printf("1 - Warrior\n2 - Mage\n");
        scanf("%d", &tmp_class);
        if (tmp_class == 1) {
            printf("Warriors are lethal in hand-to-hand combat. As a warrior you receive the following bonuses:\n 2 attack\n 1 defense\n-1 dodge\n-2 magical defense\n");
            printf("Do you really want to be a warrior?\n1 - YES\n2 - I need to think better...\n");
            scanf("%d", &confirmClass);
            if (chClass == 1) {
                extern int warriorEnUS();
            } else {
                confirmClass = 0;
                tmp_class = 0;
            }
        } else if (tmp_class == 2) {
            printf("Mages are masters in the use of supernatural forces. As a mage you receive the following bonuses:\n 2 magical attack\n-1 defense\n 1 dodge\n");
            printf("Do you really want to be a mage?\n1 - YES\n2 - I need to think better...");
            scanf(%d, &confirmClass);
            if (confirmClass == 1) {
                extern int mageEnUS();
            } else {
                confirmClass = 0;
                tmp_class = 0;
            }
        } else {
            printf("I, your narrator, am a tired old man, I have difficulty understanding some things, please select one of the two answers I asked you.\n");
            system("PAUSE");
            system("CLS");
            extern void lang_EnUS();
        }
    } while (tmp_class > 2 || tmp_class < 1);
    return 0;
}

#endif /* SELECTOR_H */

The classes header in classes.c:

#include "classes.h"
#include <stdlib.h>

//Funco para invocar e selecionar a classe de guerreiro, em lingua portuguesa
int warriorPtBR();

//Function to summon and select the warrior class in english language
int warriorEnUS();

//Funcao para invocar e selecionar a classe de mago, em lingua portuguesa
int magePtBR();

//Function to summon and select the mage class in english language
int mageEnUS();

The classes lib in classes.h:

#ifdef CLASSES_H
#define CLASSES_H

int warriorPtBR() {
    int atk = 3;
    int magicalAtk = 0;
    int defense = 3;
    int magicalDefense = 0;
    int dodge = 1;
    int healthPoints = 8;

    printf("Ao finalmente se decidir, o velho contador de historias em sua frente da um sorriso e lhe oferece uma caneca que contem um liquido borbulhante. Esta frio e voce toma, pensando em se aquecer.\n");
    printf("\nSeus pensamentos sao interrompidos quase que imediatamente, uma dor repentina surge na base da sua nuca e tudo fica escuro...\n");
}

int warriorEnUS() {
    int atk = 3;
    int magicalAtk = 0;
    int defense = 3;
    int magicalDefense = 0;
    int dodge = 1;
    int healthPoints = 8;

    printf("When you finally make up your mind, the old storyteller in front of you smiles and offers you a mug that contains a bubbly liquid. It's cold and you drink it, thinking to warm up.\n");
    printf("\nYour thoughts are interrupted almost immediately, a sudden pain appears at the base of your neck and everything goes dark...\n");
}

int magePtBR() {
    int atk = 1;
    int magicalAtk = 2;
    int defense = 1;
    int magicalDefense = 2;
    int dodge = 2;
    int healthPoints = 5;

    printf("Ao finalmente se decidir, o velho contador de historias em sua frente da um sorriso e lhe oferece uma caneca que contem um liquido borbulhante. Esta frio e voce toma, pensando em se aquecer.\n");
    printf("\nSeus pensamentos sao interrompidos quase que imediatamente, você sente uma energia potente correndo em suas veias, em seguida uma dor repentina surge na base da sua nuca e tudo fica escuro...\n");
}

int mageEnUS() {
    int atk = 1;
    int magicalAtk = 2;
    int defense = 1;
    int magicalDefense = 2;
    int dodge = 2;
    int healthPoints = 5;
    printf("Finally decide, the old storyteller in front of you a smile and offers you a mug that contains a bubbling liquid. It's cold and you take it, thinking of warming yourself. \ n");
    printf("\ nseus thoughts are interrupted almost immediately, you feel a potent energy running in your veins, then a sudden pain appears at the base of your neck and everything is dark ... \ n");
}

#endif /* CLASSES_H */

My Current output:

Hello Adventurer! Welcome to C Single Dungeon Type 1 for Portuguese, 2 for English:

When I select one of the options:

Hello Adventurer! Welcome to C Single Dungeon Type 1 for Portuguese, 2 for English: 1


Process exited after 30.72 seconds with return value 0 Pressione qualquer tecla para continuar. . .

Again, thank you very much. I hope I created my first question here at Stack Overflow in an organized way.

I appreciate all kinds of tips and advice that you can give me.

CodePudding user response:

in your classes.h header file, the first line should be #ifndef CLASSES_H. Adding this line it to make sure that classes.his not loaded twice. But in your code, since it's never been defined, it will not be defined.

  •  Tags:  
  • c
  • Related