i want

i want that every pointer from the array of the second pointers array will point only 'n' letters from the first pointers arrays..
it works with only arrays.. i dont know how to make it work with pointers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include<iostream>
using namespace std;

 main(){
	int n;
	int x = 0;
	int i = 0;
	char *st[3][20] = {"howudoing?", "whatsgoingon?", "fucku"};
	char *ch[3][20];
	
	cout << "enter a number:" <<endl;
	cin >> n;
	
	for(x = 0; x < 3; x++){
	for(i = 0; i < n; i++){
		ch[x][i] = st[x][i];
	}
	}
	for(i = 0; i < 3; i++){
	
	cout << ch[i];
	}

You should reread the comments to your previous thread, because in your current code array 'st' contains 60 pointers of which you do initialize the first three (st[0][0], st[0][1], and st[0][2]) to point to constant string literals.
But how do i touch every letter from the first pointers array without using [][] ?!
What "pointers array"? You show 2D arrays that contain pointers.

It would make more sense to have an array of pointers:
1
2
3
4
5
6
7
const char * st[] = {"howudoing?", "whatsgoingon?", "fucku"};
// The st has 3 elements. 3 pointers.
// st[0] points to string literal "howudoing?"
// st[1] points to string literal "whatsgoingon?"[
// 'h' == st[0][0]
// 'o' == st[0][1]
// 'w' == st[0][2] 

The 'ch' must be different. Pointers store addresses, but you do need space allocated for characters.
You could have an array char ch[3][20] = {0}; (conveniently initialized with null characters.
Alternatively, you'll have array of pointers and make them point to space that you allocate dynamically.

Furthermore, you don't test in you code the 'n':
1. User could write a negative number. No characters get copied, but printing uninitialized 'ch' is then an error.
2. n could be more than your shortest word.
3. n could be more than 20.
Shouldn't you name your question to your problem?
Topic archived. No new replies allowed.