Note that I would do something like:
I don't know what table[i] is, though. It may be a mere char pointer, so I used strlen. If it's an array in the local function, you may use sizeof. Otherwise you cannot.
const char query_ = "delete from where rowid=$1::int8;"
query=malloc(sizeof(query_)+strlen(tables[i]) /* null terminator counted because of sizeof */);
sprintf(query,"delete from %s where rowid=$1::int8;",tables[i]);
This should ensure you have enough space.
I doubt that your calculation is anywhere near right.