C++ ->Trying to read a line of text word by word. How to make a pointer equivalent of the current 2 dimensional array used to store the input -


wrote program read user input, word word

#include<iostream> #include<cstring>  int main() {     using namespace std; int i=0;     char input[50][50];      cout<<"enter input: ";     cin>>input[i];      while(strcmp("q",input[i]))     {         i++;         cin>>input[i];     }     cout<<endl;      for(int j=0;j<i;j++)         cout<<input[j]<<" ";     return 0; } 

currently using two-dimensional character array store input. i'm not pointers since read those.

is there pointer equivalent of char input[50][50]? know range of [50] bad idea. using pointers should solve right?

i tried doing this-> char* input= new char[50] , guess wrong way? char* input= new char[50] create pointer array of strings or pointer array of characters?

please keep simple. started arrays.

char* input= new input[50]; wrong;

char * input = new char[50]; correct.

its creates dynamic 1d array of characters. not array of pointers. if want create 2d array of characters

here syntax

char * arr = new char*[rows]; //creates 1d array of character pointers for(int i=0;i<rows;i++) arr[i]=new char[columns]; //creates array every row, make 2d array 

you can assume 2d character array 1d string array, because string character array. more suggest use strings can manipulate string.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -