the problem is that when i run it it does not trigger the 'if'. I give the debugger input parameters to be "/v /n /o" and it does not show that any of them were triggered...
as far as I THINK ArgumentInput as an array of char arrays correct? in c# the value's of vars are compared, is there a different comparison in c++?
is the format of ArgumentInput[i] something other than a char[]? and if it is, how can I convert it to one?
how do i override the default operation of the '==' sign? I make a struct with the name *char, use some inheretance with the other ^char and override their "==" operator with my "==" operator?
there is not a reason I can't, but i want to get some practice in those sort of things...
so then i shall attempt to create a char* compare myself... Thanks for the help... I might need more help in the end because of my stubbornness... Thanks you for your help... now I know that is compares the location rather than the values... big difference...
staticbool CharArrayEqual(char* First, char* Second)
{
//FirstLength represents the length of the *char First
int FirstLength;
//more represents a bool stating if there is more to the array
bool more = true;
//The for loop iterates until 'more' is false
//i represents the number of chars in the *char First (including the '\0'
for (int i = 1; more; ++i)
{
//If the char in the *char at the 'i'th element is a '\0' then more is set to false
//Else the for iterates again checking the next element for a '\0'
if (First[i-1]=='\0')
{
//Set more to false because there is not more to the *char First
more = false;
//Set FirstLength to i, which contains the int representing the position of the '\0')
FirstLength = i;
}
}
//Implement same process as above for *char Second
int SecondLength;
more = true;
for (int i = 1; more; ++i)
{
if (Second[i-1]=='\0')
{
more = false;
SecondLength = i;
}
}
//If lengths are different, then value of First is not equal to value of Second
if (FirstLength!=SecondLength)
{
returnfalse;
}
//If the lengths are the same then compare every char in First and Second
//If the two char are different then they are not equivalent
for (int i=0; i < FirstLength; ++i)
{
if (First[i]!=Second[i])
{
returnfalse;
}
}
//If the for loop iteration finishes without returning false then the values of First and Second are equal and return true
returntrue;
}
the order of the 'if's removes that problem. since the first string is checked against the second string before they are checked for a "\0" if one terminates and the other doesn't then it will return false.
my question about yours is how does it know when the *char terminates? is that the first[i] && second[i] portion? and what do those check?
is that the first[i] && second[i] portion? and what do those check?
Integers (int, short, char, etc.) can be converted to booleans. 0 evaluates to false and everything else evaluates to true. if(x) is equivalent to if(x!=0)
'\0' is not really a special character like many seem to think. A backslash (\) followed by numerical digits merely provide a way to input literal numerical values into a string (in octal).
The character '\0' has a literal value of 0. Therefore the below two lines are exactly the same:
1 2
char null = '\0';
char null = 0;
So '\0' is equal to 0, just like '\5' is equal to 5.