For example if the string is:
XYZ ::[1][20 BB EC 45 40 C8 97 20 84 8B 10]
The output should be:
20 BB EC 45 40 C8 97 20 84 8B 10
int main()
{
char input = "XYZ ::[1][20 BB EC 45 40 C8 97 20 84 8B 10]";
char output[500];
// what to write here so that i can get the desired output as:
// output = "20 BB EC 45 40 C8 97 20 84 8B 10"
return 0;
}
In C, you could do this with a scanset conversion (though it’s a bit RE-like, so the syntax gets a bit strange):
In case you’re wondering how that works, the first
[matches an open bracket literally. Then you have a scanset, which looks like%[allowed_chars]or%[^not_allowed_chars]. In this case, you’re scanning up to the first], so it’s%[^]]. In the first one, we have a*between the%and the rest of the conversion specification, which meanssscanfwill try to match that pattern, but ignore it — not assign the result to anything. That’s followed by a]that gets matched literally.Then we repeat essentially the same thing over again, but without the
*, so the second data that’s matched by this conversion gets assigned tosecond_string.With the typo fixed and a bit of extra code added to skip over the initial
XYZ ::, working (tested) code looks like this: