cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Windows Programming : Strcmp being dumb...
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  Strcmp being dumb...

SnapCrakllPop (13)
That was a stupid title, but it's what's happening...I think.

I'm trying to get the first argument after the program name (argv[1]) and see if it is "mute" or "unmute."

Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

int main(int argc, char *argv[])
{
	if(argc == 0)
	{
		cout << "No args!";
	}
	else
	{
		if(strcmp("unmute", argv[1]) != 0)
		{
			cout << "Requested operation: unmute\n";
			cout << "argv[1] reads: " << argv[1];
		}
		else if(strcmp("mute", argv[1]) != 0)
		{
			cout << "Requested operation: mute\n";
			cout << "argv[1] reads: " << argv[1];
		}
		else
			cout << "ERROR";
	}
	return(0);
}


For some reason, no matter what I type, this is my output:
1
2
3
4
5
6
7
8
9
I:\system\debug> system mute
Requested operation: unmute
argv[1] reads: mute
I:\system\debug> system unmute
Requested operation: unmute
argv[1] reads: unmute
I:\system\debug> system wtf
Requested operation: unmute
argv[1] reads: wtf


Anyone have any ideas?

Thanks
|
firedraco (847)
strcmp() returns 0 if the two values match.
|
SnapCrakllPop (13)
Leave it to me to flip the values :'(

Thanks a lot firedraco!
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us