cstr = new char [nameOfEle.size()+1];
strcpy (cstr, nameOfEle.c_str());
int count = 0;
token[0] = strtok(cstr, "_.");
while (token[count] != NULL)
{
count++;
token[count] = strtok (NULL, "_.");
}
for (int i = 0; i <= count -1 ; i++)
{
printf ("%s \n", token[i]);
}
char hf.nameOfE[] = token[0];
printf("\nThis is name of material= %s\n",hf.nameOfE);
strcat(hf.nameOfE, "_"); //HERE GIVES ERROR AS Parameter miss match
cout << "After adding :: " << hf.nameOfE<< endl;
}
Thanks a lot for help. It works. But if I do strcat further then its not working. I don't know why? As per logic it should work.
I am trying to do :
hf.nameOfE = token[0];
printf("\nThis is name of material= %s\n",hf.nameOfE);
strcat(hf.nameOfE, "_");
cout << "After adding :: " << hf.nameOfE<< endl;
//This part I am trying to add
hf.secondElement = token[1];
strcat(hf.nameOfE,hf.secondElement); //Its not working
cout << "Further addition of strings:" << hf.nameOfE << endl; //The output is: ABC_. But I was expecting ABC_def.
The problems arise because the class headerFile uses simple pointers.
Then when you do strcat() you are actually trying to change whatever the pointer is pointing to. In other words, it is trying to change the list of tokens.
I think you need to allocate some space so that headerFile will keep its own separate data.