I had a question concerning the use of dynamic char arrays with the constructor of a class. Here, I have a class in which I pass a name that will be stored in a dynamically created char array. Since the array size can vary depending on the name passed to the constructor, I am not sure what steps to use to allocate the correct array size. I wish to avoid using string and the STL. Here is what I have so far and it's almost complete except for the name.
Alright, first thing is first: Don't you dare call yourself L. I will write your name down, for you see, I have the eyes; I can see your name above your post. (Seriously though, it's stupid)
Anyway, why on Earth would you want to avoid the ease of strings? The STL too? WHY!?
I cannot think of any way to just take the number of elements from an array. You'd have to use something like vectors, or strings.
What the hell? Remove strings is one thing, but to put an end to things like iterators, no.
constchar foo[] = "whatever";
int foolen = strlen( whatever );
char* bar = newchar[ foolen + 1 ]; // add 1 for the null terminator!
strcpy( bar, foo ); // copy foo to bar
I wish to avoid using string and the STL
May I ask why? No point in making things harder on yourself.
As part of an algorithm class, we are studying how someone might create an algorithm to do, for example, what a string might do. It is the instructor's request NOT to use string and the STL and I quote, "...if you do you will get zero points." Sounds like a good enough reason to me.