hi, if i want to get the length of argv1 and 2 and compare it against a value for an if statement , why does the following not work ? if (strlen(argv[1]) && strlen(argv[2]) >info, char fullname[20]; or if (strlen(argv[1]) && strlen(argv[2])
hi, if i want to get the length of argv1 and 2 and compare it against a value for an if statement , why does the following not work ? if (strlen(argv[1]) && strlen(argv[2]) >info, char fullname[20]; or if (strlen(argv[1]) && strlen(argv[2])
The result of operator && is an int with a value of 0 or 1.
When you do
strlen(argv[1]) && strlen(argv[2])
you will get, almost 100% certainly, 1, so
if (1 > info)
will only be true if info <= 0
Welcome to the forum, cahce!
It's pretty useless to fight to read code after the forum software has chewed it up. Use code tags to surround all your code.
The advanced editor has an icon - just hilite your code and click on it, or you can add your own, if in quick reply mode.
And "or" is not a C keyword. Maybe you want || ?Code:if (strlen(argv[1]) && strlen(argv[2]) >info, char fullname[20]; or if (strlen(argv[1]) && strlen(argv[2]) Best to break it up, closing the comparison after "info" ) { state your actions if that comparison is true } else { make the code here for when the comparison is false. }
Maybe you meant:
if (strlen(argv[1]) > info && strlen(argv[2]) > info)