Search code examples
c++segmentation-faultmemory-segmentation

C++ segmentation error in 2D array assignment


I am receiving segmentation error in the following code. I am not quite aquainted with this error.

cout<<"r="<<r<<"c="<<c<<endl;
int i=0,k=0;
for(int k=0;k<r;k++)
    for(int j=0;j<c,str[i]!='0';j++)
        {
         (newl[k][j]=str[i]);  //shows segmentation error on debugging
          cout<<str[i];i++;

        }

Could any one point out whats the mistake i am making?


Solution

  • '0' is literally the character for the digit "zero".

    The nul-terminator that marks the end of a C-string is '\0'.