How to Assign a Phrase to a row in an array of chars?

-1

I want to modify standard phrases from a theoretical game. For example, the game has the phrase "Choose a command" and, over a given state, you would like to change all the letters "o" and "a" by an @.

For this, I thought about implementing an array of characters,

Speeches [100] [500], which can store 100 500-character phrases.

I want to assign to speech [1] "Choose an action", you say [2] "You can not go there", etc.

And to do what I want to do, since the player is in such a state, I would use sscanf in phrase [x] [] and run the whole sentence [x] [i], with i going from 0 to strlen phrase [x].

However, I can not even assign and do not know how to print these sentences.

The first problem is not knowing how to include '\ 0' at the end of a typed string within the program. At the same time,% s should work until you find the first \ 0 in the memory garbage, and you are only printing a random character in the program below:

#include<stdio.h>

int main (){

   char falas [100][500];

   falas[1][0] =  "Seja bem vindo ao meu jogo";

   printf("%s", falas[1]);

}
    
asked by anonymous 04.10.2018 / 18:26

1 answer

-1

You can assign using strcpy which is in include cstring . That way the code you put as an example should look like this:

 #include <stdio.h>
 #include <cstring>

int main() {

    char falas[100][500];

    strcpy(falas[0], "Seja bem vindo ao meu jogo");

    printf("%s", falas);
}
    
04.10.2018 / 19:18