Exercise with Indefinite Matrix of Strings

Asked

Viewed 27 times

1

I am trying to do an exercise where the user through a random sequence decides the size of the Board (Matrix) and how the values will be organized. Because it is a game where the 3 Robots(Recognized in the matrix by the Initials) and they must reach a portal.

My doubt is how to find these Strings A,B,C inside the matrix and when the user gives a command to move the robots, I can change in the matrix only those values, follows here the main structure of the Code:

main()
{
    system("color 0B");
    int lin, col, i,j;
    printf("Qual sera o tamanho do tabuleiro MxN:");
    scanf("%i",&lin);
    col = lin;
    char m[lin][col];
    system("Cls");
    printf("Neste Jogo voce decide como sera o tabuleiro!!\n");
    printf("Nele deve haver as inciais dos 3 robos\n");
    printf("Os # serao os obstaculos, X sera os portais e '.' sao casas 
    vazias.\n");
    printf("Faca uma sequencia com esses digitos e bom jogo");

    for(i=0; i<lin; i++)
    {
        for(j=0; j<col; j++)
        {
            printf("\nDigite a sequencia [%d][%d]: ",i,j);
            scanf("%s",&m[i][j]);
        }
    }

    printf("\n\nSeu tabuleiro e: \n");
    for(i=0; i<lin; i++)
    {
        printf("  %c", 'A'+i);
    }
    printf("\n");
    for(i=0; i<lin; i++)
    {
        printf("\n");
        printf("%c",'A'+i);
        for(j=0; j<col; j++)
        {
            printf("[%c]",m[i][j]);
        }
    }

}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.