system() in C gives unrecognized command error, while using the same command in CMD works

I have this straightforward code here:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    system("msg "%username%" hi there");
    return 0;
}

The program throws this error:

'msg' is not recognized as an internal or external command,
operable program or batch file.

However when I just copy-paste the command in cmd and run it(excluding the backslash()s) like this:

msg "%username%" hi there

It doesn’t throw any kind of “unrecognized command” error and works finely:

enter image description here

What can be wrong? How can I fix it? I have also read some related discussions: question1, question2, etc. But these didn’t help me(probably because I didn’t understand them, rather than they answered unclearly).

What can be wrong? How can I fix it?

Thanks!