Canc code c++

Fixed seg fault
C++ code

Fixed seg fault