0

This line creates an array body of size [(strlen(template) - 2 - ((int) log10(code) + 1) - 2 + strlen(phrase)) * 2 + 1].

// render template
char body[(strlen(template) - 2 - ((int) log10(code) + 1) - 2 + strlen(phrase)) * 2 + 1];
int length = sprintf(body, template, code, phrase, code, phrase);

But, I am unable to understand why "(strlen(template) - 2 - ((int) log10(code) + 1) - 2 + strlen(phrase))" has been multiplied by 2.

According to me, it should have been as

char body[strlen(template) + (-2 + ((int) log10(code) + 1) - 2 + strlen(phrase)) * 2 + 1];
0

1 Answer 1

1

Yes, I agree. I suspect it was a mistake in the code, but because it allocates a larger than necessary body, it causes no problems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .