|
-
Nov 5th, 2002, 02:01 PM
#1
Thread Starter
<?="Moderator"?>
runs all ifs??? [*resloved*]
Code:
if(argc>2)
{
if(argv[1]="open")
{
...
}
else if(argv[1]="new")
{
...
}
}
when i enter in "cmdline.exe open c:\test.txt", it runs fine, when i run £cmdline.exe new c:\newtext.txt" it trys to open c:\newfile.txt? is this because im trying to use a string in the "if(argv[1] = ..." part??
Thanks
Last edited by john tindell; Nov 5th, 2002 at 03:41 PM.
-
Nov 5th, 2002, 02:09 PM
#2
Frenzied Member
You are using the assignment operator in the if statement. You MEANT ==.
Second, unless you converted your command line arguments to string objects in C++, you cant use the == operator to determine equality of the strings. Use the strcmp function instead.
Z.
-
Nov 5th, 2002, 02:32 PM
#3
Hyperactive Member
-
Nov 5th, 2002, 03:24 PM
#4
Frenzied Member
Yeah, though you dont have to store those strings before using them in the strcmp function... you can simply call it like so:
Code:
strcmp(argv[1], "new") == 0
Z.
-
Nov 5th, 2002, 03:41 PM
#5
Thread Starter
<?="Moderator"?>
cheers thanks for the help
-
Nov 5th, 2002, 03:50 PM
#6
Monday Morning Lunatic
<iostream> not <iostream.h>.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|