0

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;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Agni
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.