cout groks strings that end in zero. You can print them with cout << char_array_variable<< without looping 1 char at a time.
eg cout << destination << endl is the same as a loop over destination[i].
'\0' is fancy for 0 . if you prefer the explicit form, that is fine.
I don't see anything right off except this:
Passenger(nullptr, nullptr),
and I have to wonder if you are crashing trying to access this or one of the other partly null entries. I suspect the issue is that you have confused a null pointer and an empty string.
char *cp = nullptr;
if(cp[0] == 0) //fail: cp CANNOT be accessed at all! It is NOT the empty string.
char cp[10] = {0};
if(cp[0] == 0) //OK. Cp is the empty string.
specifically your function isempty tries to access unallocated pointers, if i followed your code correctly (just looking at it, I didnt compile and all that yet). I am not 100% sure, name and dest are not pointers so this may be failure to follow the code on my part.
It may also be your constructor. The constructor checks both being null and if either are ... it does nothing, and that leaves destination and name uninitialized, this could be the source of the crash as well.
I think you need to add an else to the char* version of the ctor that sets them to empty string if not valid inputs.
Why are you trying to copy each individual character from one string to the next instead of just using strcpy() instead? Edit: If you stay with your current approach don't forget to properly terminate those strings.
And because you're trying to pass nullptr as some of the parameters you need to be careful not to try to use those parameters when they are set to nullptrs.
You also have quite a few warning: deprecated conversion from string constant to ‘char*’ warnings in main(), caused by the following:
Line 3: You can't compare C-strings like that. e.g. nameString and "" are pointers. You're comparing the pointers. Not the strings. The == operator operator only works with C++ strings.
How would you recommend I fix this (Im getting the below warnings)? I have no idea how to go about this, we werent taught of this error in my class (yet, I guess).
jlb,
I did, now it all compiles and runs, but Im still getting the errors. warning: deprecated conversion from string constant to ‘char*’
and warning: comparison with string literal results in unspecified behaviour
And when I change the definition and implementation to, Passenger::Passenger(constchar* nameString, constchar* destinationString);
I get the error, unresolved external symbol "public: __this call sict::Passemger::Passenger(char *, char *)" (??0Passenger@sict@@QAE@PAD0@Z) referenced in function _main
Here, you are comparing a pointer to a pointer. You are NOT, repeat NOT, checking if the string represented by nameString is blank.
A pointer is a memory address. "" is interpreted as a char-pointer, nameString is a different char-pointer. You are comparing two memory addresses to see if they're the same memory address. I suspect this is not what you intended.
The short answer is don't use char*. This isn't C. If you want a string, use a string.
The longer answer is spend time learning about pointers and char arrays and char pointers, and then don't use them; if you want a string, use a string.