Is it possible to use a dynamic c-string instead of a []

Disclaimer: this is for a linked list for homework, as you can see this is just a tiny aspect of a larger problem. I am not asking for anyone to help me write this assignment.


I would like have name1 and name2 be allocated dynamically using c-strings?
Is this possible?


In this signature I am passing two objects to an overloaded bool operator.
Thinking about this I would just need a strlen function in my object class, but I have tried this and it is not working as expected. any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
bool operator<(const item& a_item, const item& b_item)
{
  char name1[100];
  char name2[100];
    
  a_item.getName(name1);
  b_item.getName(name2);

  if(strcmp(name1, name2) < 0)
    return true;
  else
    return false;
}
I think I solved it.

1
2
3

   char *name2 = new char[b_item.getNameLen()];
Topic archived. No new replies allowed.