How can we receive pointer array with cin ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can we receive pointer array with cin ?

I define : char *s [5] ; int i = 0; for ( i <0 ; i++) cin >> s [i]; but it doesn't run and it has bug

21st Jan 2018, 1:50 PM
Blck_brry
1 Answer
+ 2
Your for loop has errors. You need to add the semicolon before the condition and the condition must be i<5. => for(;i<5;i++) cin>>s[i]; And secondly, to read a string inside a character pointer, you need to allocate memory for its characters before reading. => for(;i<5;i++) {s[i]=new char[30]; cin>>s[i];}
21st Jan 2018, 2:28 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar