Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to cut down my file lines by having one variable to insert into several arrays. So I'd like to have a string, or an array variable, such as the following:

new combomeals[] = { 
    3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, 
    3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, 3021701, 3021700, 3020602, 
    3021601, 3030100, 3021600, 3021502, 3021501, 3020201, 3021500, 3020150, 3020502, 3020501, 
    3020500, 3001802, 3001801, 3001800, 3001702, 3001701, 3001700, 3011602, 3011601, 3011600, 
    3011502, 3020202, 3011501, 3011500, 3011232, 3011231, 3011202, 3011201, 3010602, 3010601, 
    3010600, 3010902, 3010901, 3010900, 3011102, 3011101, 3011100, 3011002, 3011001, 3011000, 

}

It's actually much longer than that, but I shortened it for the explanation... I want to take combomeals[] and put that into other arrays. The following does not work, but you will get the idea:

new first_array[] = { 1, 2, 3, combomeals[], }

new second_array[] = { 4, 5, 6, combomeals[], }

new third_array[] = { 7, 8, 9, combomeals[], }

The end goal is to put the first array into several other arrays. Please let me know if this makes sense and if you are able to help!

Thank you!

share|improve this question
What specific part are you having problems with? – Armin yesterday
Putting combomeals[] into other arrays. I want first_array[] to print 1, 2, 3, 3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, 3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, etc, etc ,etc... Right now I get a syntax error. – Gonzo's Memoirs yesterday
I suggest you fix the error. – Armin yesterday
... I am actually wondering HOW to do this? The error I get is because I am not sure how to do this sort of thing in a pawn script. I am really trying to do something like this: char str1[100] = "Hello,"; strcat(str1, " world!"); to get "Hello world!"... Do you understand? – Gonzo's Memoirs yesterday
Error is: invalid expression, assumed zero – Gonzo's Memoirs yesterday
show 1 more comment

1 Answer

You cannot extend an array in the way you are attempting. Assuming that new has been aliased to an integral type, then the compiler will only accept the initializer list for first_array if all the elements in the list are the same type. But the last element of the list is a syntactic error, as combomeals is an array, and combomeals[] doesn't belong in an initializer list.

Similarly for the second_array and third_array.

You can accomplish something similar by putting the numbers in combomeals into a macro instead:

#define COMBOS \
3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, \
3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, 3021701, 3021700, 3020602, \
3021601, 3030100, 3021600, 3021502, 3021501, 3020201, 3021500, 3020150, 3020502, 3020501, \
3020500, 3001802, 3001801, 3001800, 3001702, 3001701, 3001700, 3011602, 3011601, 3011600, \
3011502, 3020202, 3011501, 3011500, 3011232, 3011231, 3011202, 3011201, 3010602, 3010601, \
3010600, 3010902, 3010901, 3010900, 3011102, 3011101, 3011100, 3011002, 3011001, 3011000,

new combomeals[] = { COMBOS };

new first_array[] = { 1, 2, 3, COMBOS };
new second_array[] = { 4, 5, 6, COMBOS };
new third_array[] = { 7, 8, 9, COMBOS };

If your compiler has trouble dealing with a long source line, you may have to split COMBOS apart. It is less convenient, but a c89 compiler is only required to support a source file length 509 bytes long.

#define COMBOS1 \
3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, \
3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, 3021701, 3021700, 3020602, \
3021601, 3030100, 3021600, 3021502, 3021501, 3020201, 3021500, 3020150, 3020502, 3020501
#define COMBOS2 \
3020500, 3001802, 3001801, 3001800, 3001702, 3001701, 3001700, 3011602, 3011601, 3011600, \
3011502, 3020202, 3011501, 3011500, 3011232, 3011231, 3011202, 3011201, 3010602, 3010601, \
3010600, 3010902, 3010901, 3010900, 3011102, 3011101, 3011100, 3011002, 3011001, 3011000

new combomeals[] = {
    COMBOS1,
    COMBOS2,
};

new first_array[] = {
    1, 2, 3,
    COMBOS1,
    COMBOS2,
};

/* ...etc... */

You may need to further break down the lines if your C compiler is non-conforming.

share|improve this answer
I believe this will work... Thank you so much for understanding... Now I have another issue though - 6/14 16:42:55:: LOG - 20130614164255.000 | TEST.p(166) : error 075: input line too long (after substitutions). I get that at least 20 times. I tried shortening the length of each row, but it makes no difference. Thoughts? – Gonzo's Memoirs yesterday
I limited each number to one line, still not working. 1, \ 2, \ 3, \ – Gonzo's Memoirs yesterday
@Gonzo'sMemoirs: You have to split the line apart itself, not the macro. The macro just becomes one long line. See my updated answer. – jxh yesterday
I'm not quite sure what you mean... I had it on 98 separate lines followed by "\" and this did not work... I tried with 196 lines and half the line characters, this did not work either. Perhaps I just don't understand what you mean. – Gonzo's Memoirs yesterday
Actually, I did something like what your modified edit was... but 98 times... It tried to load for a very long time, and never finished. I think this is a 'correct' answer, but I can't get it to run in my system (probably because this file is gigantic). – Gonzo's Memoirs yesterday
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.