The CString
constructor attempts to copy a null-terminated string from the input argument (more precisely, from the memory address pointed by the input argument).
So it copies characters until reaching a 0 (null) character, and since the contents of R[5000]
are not initialized, there's a good chance that none of the characters in it is equal to 0.
If there is no such character within the legal memory region pointed by the input argument, then the CString
constructor exceeds that memory region, and most likely causes an illegal memory access.