This is the code segment I hv written. But its compiling well. but it doest give expected output, for me..

I want to write a function to split a char array by taking "," as the delimeter.
I m not splitting the array at once. I m doing it one by one by calling the GetSection function.

char * GetSection(char **Message, char Delimeter)
{
char * Section;

     *Message = strtok (*Message,",");
    printf ("%s\n",*Message);
  Section = *Message;
  **Message = NULL;
  return Section;
  	
}

void Split(string Message)
{
	unsigned int counter	= 1;
	char Delimeter = ',';
	char * ArrayMessage;
	string tempValue;
	stringstream InputData;	

	ArrayMessage = new char [Message.size()+1];
	strcpy (ArrayMessage, Message.c_str());
	
	m_szCommandName = GetSection(&ArrayMessage, Delimeter);
	  printf ("%s\n",m_szCommandName);

	//delete []ArrayMessage;
	InputData<<command;
	GetLine(InputData, m_szCommandName, MSGDELIMETER);

	//convert commandName(String type) into hexadecimal format
	stringstream convert ( m_szCommandName ); 
	convert>> std::hex >> m_nCommandID;
	cout<<m_nCommandID;
}

1-> What is the expected output?
2-> What's the output you're getting right now?
3-> Post the complete code
4-> Please use code tags to make you're code readable

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.