How to read from array
#1

Alright so, I need small advice how to read from this array

new Fruits[][512] = {
{"Fruits1","Tomato","Apple","Citron"},
{"Fruits2","Cherry","Mango","Orange"}
};


printf("%s are: %s %s %s",Fruits[0],....

printf("%s are: %s %s %s",Fruits[1],....


so how to read from Fruits array?
Reply
#2

You've pretty much guessed it right. You specify the cell in the 1st dimension to get the contents of it, for example:

pawn Код:
printf("Fruits are: %s, %s, %s, %s", Fruits[0], Fruits[1], Fruits[2], Fruits[3]);
// Fruits are: Fruits 1, Tomato, Apple, Citron
Hope that helps!
Reply
#3

But it will print Fruits1 and then only 1st chars from the rest

in console will be " Fruits1 are T A C " as its prints single character of Fruits[2],Fruits[3],..
Reply
#4

How do you want to read it? When you do Fruits[0] do you want to see "Fruits1 Tomato Apple Citron"?

If so your array should be like this.

pawn Код:
new Fruits[][] =
{
    {"Fruits1 Tomato Apple Citron"},
    {"Fruits2 Cherry Mango Orange"}
};
Reply
#5

Fruits I took as example, I want to pick random RP question.


like

new Fruits[][512] = {
{"Fruits1","Tomato","Apple","Citron"},
{"Fruits2","Cherry","Mango","Orange"}
};

new r = random(sizeof(Fruits));

SendClientMessage(playerid,COLOR,Fruits[r][0]);//Question
SendClientMessage(playerid,COLOR,Fruits[r][1]);//Answer A
SendClientMessage(playerid,COLOR,Fruits[r][2]);//Answer B
SendClientMessage(playerid,COLOR,Fruits[r][3]);//Answer C

But only Fruits[r][0] works as need, rest its print as signle char
Reply
#6

Use it like this.
pawn Код:
SendClientMessage(playerid,COLOR,Fruits[r]);//
Don't add second dimension if you index the second dimension you are getting a char, if you don't use the second dimension all of the string will be used.
Reply
#7

Still doesnt help as I want that its also picks 3 answers of each question
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)