copying char array contents into char pointer array

hello every one am new to this forum..
and i need urgent help regarding how to copy contents of char data[100] to char* items[100]
its urgent ..


thanks regards
yakub pasha
Hey dude,

here is your answer *tada*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream> // for std::I/O
#include <cstring> // for std::strcpy


int main ( )
{
	char Data[100] = "An important mail..."; // Initializing
	char* Items[100] ; 
	
	Items[0] = new char[100] ; // We have to allocate for each Item memory.
	
	std::strcpy(*Items,Data) ; // Here we copy it
	std::cout << Items[0] << std::endl ; // Just for 'DEBUG'
	
	delete[] Items[0] ; // And free it -> Else Memory leak
}


bye and have fun (:
thank you very much.. i'll try this..
Topic archived. No new replies allowed.