954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Returns null pointer

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;
}
savinki
Light Poster
29 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

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

Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You