get a integer from char* ...?

Actually, you should use the length returned from the call (len) to set the null. Change the null assignment to:

msg[len] = '\0';