c++ problem O:

11/13/2008 16:19 EXTEЯNAL#1
hey guys, i just started with learning and here is my first problem

Code:
#include <iostream>

using namespace std;

void main()
{
	printf("Started...\n");
     char get[255];
     while(true)
	 {
		  cin >> get;

          if(strcmp(get,"/flash 1") == 1)
          {
               // blabla
          }
          else if(strcmp(get,"/flash 0") == 1)
          {
               // oO
          }else{
          printf("%s is not a vaild command!\n",get);
          }
     }
}

now when i type in console "/flash 1" i get %s is not a vaild command -_-, anyone know how to fix it? i can do /flash1 but i wont do it so, i hope anyone know the problem ~.~
11/13/2008 22:53 Bot_interesierter#2
Doesn't strcmp return zero if the strings are equal?
maybe that's your mistake :-)
11/14/2008 08:13 neji#3
Quote:
Originally Posted by Bot_interesierter View Post
Doesn't strcmp return zero if the strings are equal?
maybe that's your mistake :-)
yep
11/14/2008 09:19 Cholik#4
true, true ;e

[Only registered and activated users can see links. Click Here To Register...]
11/14/2008 12:02 bloodx#5
probiers mal mit :

void main()
{
printf("Started...\n");
char get[255];
while(true)
{
cin >> get;

if(strcmp(get,"/flash 1") == 0)
{
printf("Working \n");
}
if(strcmp(get,"/flash 0") == 0)
{
printf("Off oO ßn");
}
else{
printf("%s is not a vaild command!\n",get);
}
}
}
11/14/2008 23:24 ntKid#6
Code:
#include <iostream>

using namespace std;

void main()
{
	printf("Started...\n");
	
	while(true)
	{
		char* get = new char[255];
		
		std::cin.getline(get,255);

		if(strcmp(get,"/flash 1") == 0)
		{
			printf("Got %s\n",get);
		}
		else if(strcmp(get,"/flash 0") == 0)
		{
			printf("Got %s\n",get);
		}else{
			printf("%s is not a valid command!\n",get);
		}
		delete get;
	}
}
or

Code:
void main()
{
	printf("Started...\n");

	while(true)
	{
		char* get = new char[255];

		cin >> get;

		if(strcmp(get,"/flash")==0)
		{
			int bResult;

			cin >> bResult;

			if(bResult==0)
				printf("%s %d = Off\n",get,bResult);
			else if(bResult==1)
				printf("%s %d = On\n",get,bResult);
			else
				printf("%s %d not a vaild argument!\n",get,bResult);
		}
		else
		{
			printf("%s is not a vaild command!\n",get);
		}
		delete get;
	}
}
11/15/2008 12:37 EXTEЯNAL#7
mhm thanks for the effort guys, but using just cin >> will only store the input until i hit a space, then it cuts the rest off...

just using cin.getline(), works perfect


theard can be close ;)
11/16/2008 14:02 unknownone#8
Can i just point out, since you're just learning, learn properly.

main returns an int, not void. That should be return 0, or EXIT_SUCCESS.

Although most compilers will compile void main() fine, it's not standard, and may not be portable for any system. Returning void might assume the program didn't execute successfull etc. Stick to standards :p

Also reccomend using cout << rather than printf. Not too important though, just don't see why you're mixing C++ stl and C libraries.