Thread: Hangman game

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    6

    Post Hangman game

    This is a part of my project.




    I need to register and that after registering go back to the main (menu) and that the login go get the values ​​to main to validate the user and pass.


    Can you help me? Thank you

    __________________________________________________ _____
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <locale.h>
    #include <string.h>
    
    
    void login(int utilizador);
    void registo();
    
    
    int main()
    {
        setlocale(LC_ALL,"");
        char op, utilizador[30];
        do {
            printf("|'''''''''''''''|\n");
            printf("| Jogo da Forca |\n");
            printf("|...............|\n\n");
    
    
            printf("E - Entrar\n");
            printf("R - Registar\n");
            printf("S - Sair\n\n");
            fflush(stdin);
            printf("Escolha uma opção: ");
            scanf(" %c", &op);
            op = toupper(op);
            if (op == 'E')
                {
                system("CLS");
                login(utilizador);
                }
            if (op == 'R')
                {
                system("CLS");
                registo();
                }
            }
        while (op == "S");
        system("EXIT");
    }
    
    
    void login(int utilizador){
        int id;
        char utiliza[30], pass[30];
    
    
        printf("|'''''''''''''''|\n");
        printf("| Jogo da Forca |\n");
        printf("|...............|\n\n");
    
    
        printf("LOGIN\n\n");
        printf("Introduza o seu ID: ");
        scanf(" %d", &id);
        printf("Introduza o Utilizador: ");
        scanf(" %s", &utiliza);
        printf("Introduza a Password: ");
        scanf(" %s", &pass);
        jogo();
        return 0;
    }
    
    
    void registo(){
        char novoutiliza[30], novapass[30];
    
    
        printf("|'''''''''''''''|\n");
        printf("| Jogo da Forca |\n");
        printf("|...............|\n\n");
        printf("REGISTO\n\n");
        printf("Introduza o Utilizador: ");
        scanf(" %s", &novoutiliza);
        printf("Introduza a Password: ");
        scanf(" %s", &novapass);
        printf("\nREGISTADO COM SUCESSO");
        getch();
        system("CLS");
        main();
        return 0;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,541
    You want something to preserve the details from one call to another.

    Say
    Code:
    struct user {
        int id;
        char name[20];
        char pass[20];
    };
    
    int login(struct user *user);
    void registo(struct user *user);
    
    int main ( ) {
        struct user user;
    
        // register first
        registo(&user);
    
        // then try and login
        if ( login(&user) ) {
            // login success
        } else {
            // login failed
        }
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Ok, ty.

  4. #4
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Salem, I really can not do it. I need more than one user to register...

    Code:
    #include <stdio.h>#include <stdlib.h>
    #include <locale.h>
    #include <string.h>
    
    
    struct utilizador
        {
            int id;
            char nome[20];
            char pass[20];
        };
    
    
    int login(struct utilizador *utiliza);
    void registo(struct utilizador *utiliza);
    void jogo();
    
    
    int main()
    {
        setlocale(LC_ALL,"");
        char op, utilizador[30];
        struct utilizador utiliza;
        do {
            printf("|'''''''''''''''|\n");
            printf("| Jogo da Forca |\n");
            printf("|...............|\n\n");
    
    
            printf("E - Entrar\n");
            printf("R - Registar\n");
            printf("S - Sair\n\n");
            fflush(stdin);
            printf("Escolha uma opção: ");
            scanf(" %c", &op);
            op = toupper(op);
            if (op == 'E')
                {
                system("CLS");
                login(&utiliza);
                }
            if (op == 'R')
                {
                system("CLS");
                registo(&utiliza);
                }
            }
        while (op == "S");
        system("EXIT");
    }
    
    
    int login(struct utilizador *utiliza){
        int id;
        printf("|'''''''''''''''|\n");
        printf("| Jogo da Forca |\n");
        printf("|...............|\n\n");
    
    
        printf("LOGIN\n\n");
        printf("Introduza o seu ID: ");
        scanf(" %d", &id);
        printf("Introduza o Utilizador: ");
        scanf(" %s", &utiliza);
        printf("Introduza a Password: ");
        scanf(" %s", &pass);
        jogo();
        return 0;
    }
    
    
    void registo(struct utilizador *utiliza){
        printf("|'''''''''''''''|\n");
        printf("| Jogo da Forca |\n");
        printf("|...............|\n\n");
        printf("REGISTO\n\n");
        printf("Introduza o Utilizador: ");
        scanf(" %s", &utiliza.nome);
        printf("Introduza a Password: ");
        scanf(" %s", &utiliza.pass);
        printf("\nREGISTADO COM SUCESSO");
        getch();
        system("CLS");
        main();
        return 0;
    }
    I really can not do it.
    Last edited by daviddiniss; 12-21-2018 at 08:43 AM.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,541
    > I need more than one user to register...
    So make your users an array then.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hangman Game
    By Mcdom34 in forum C# Programming
    Replies: 3
    Last Post: 10-13-2012, 11:21 AM
  2. Hangman game
    By Dontgiveup in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2011, 04:44 PM
  3. Help with hangman game.
    By astarialexi in forum C Programming
    Replies: 8
    Last Post: 03-13-2011, 04:04 AM
  4. Hangman Game - Need Help!!
    By krobort in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2006, 04:15 PM
  5. New game: Hangman!
    By abrege in forum Game Programming
    Replies: 6
    Last Post: 12-05-2002, 02:05 PM

Tags for this Thread