Warning: comparison with string literals results in unspecified behaviour
You want to use strcmp() == 0
to compare strings instead of a simple ==
, which will just compare if the pointers are the same (which they won't be in this case).
args[i]
is a pointer to a string (a pointer to an array of chars null terminated), as is "&"
or "<"
.
The expression argc[i] == "&"
checks if the two pointers are the same (point to the same memory location).
The expression strcmp( argc[i], "&") == 0
will check if the contents of the two strings are the same.
There is a distinction between 'a'
and "a"
:
-
'a'
means the value of the charactera
. -
"a"
means the address of the memory location where the string"a"
is stored (which will generally be in the data section of your program's memory space). At that memory location, you will have two bytes -- the character'a'
and the null terminator for the string.