Skip to content

Dynamic length string array #2017

Answered by WerWolv
ni-ko-b asked this question in Get Help
Discussion options

You must be logged in to vote

Hey! Something like this should work for you I believe

struct NewLineTerminatedString {
    char string[while($[$] != '\n')];
    char newLine;
};

struct StringList {
    u32 numEntries;
    NewLineTerminatedString strings[numEntries];
};

StringList list @ 0x08;

This defines a type called NewLineTerminatedString which contains an array that keeps expanding until it hits a new line character. Then, since it stopped when reaching that character, it places another char down to catch that.

Then we simply create an array out of that type, given the array length value as the size of the array :)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ni-ko-b
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants