c++ - problems with printing 2d array from print function -


i'm trying fill , print 2d array, yet every time try compile says undeclared identifier c. , points arrow @ c in print function. tried declaring many ways yet reason not work.

#include <iostream>  using namespace std;  void print(char x[][c], int r) {     for(int r  = 0; r < 25; r++)     {         for(int c = 0; c < 25; c++)         {           cout << x[r][c];          }          cout << endl;         }  }  int main() {     void print(char x[][c], int r);      char p[25][25];      for(int r = 0; r < 25; r++)     {          for(int c = 0; c < 25; c++)         {             if(r==0)p[r][c]='x';             else    p[r][c]='o';         }         }         print(p[25][25]);       return(0); } 

write following way

#include <iostream>  using namespace std;   const size_t rows = 25; const size_t cols = 25;  void print(char x[][cols], size_t r ) {     ( size_t  = 0; < r; i++ )     {         ( size_t j = 0; j < cols; j++ )         {           cout << x[i][j];          }          cout << endl;         }  }  int main() {     char p[rows][cols];      ( size_t = 0; < rows; i++ )     {         ( size_t j = 0; j < cols; j++ )         {             if ( == 0 ) p[i][j] = 'x';             else p[i][j] = 'o';         }         }         print( p, rows );       return(0); } 

another approach define function following way

void print( char ( &x )[rows][cols] ) {     ( size_t  = 0; < rows; i++ )     {         ( size_t j = 0; j < cols; j++ )         {           cout << x[i][j];          }          cout << endl;         }  } 

and call like

    print( p ); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -