|
You last visited: Today at 17:56
Advertisement
c++ problem O:
Discussion on c++ problem O: within the C/C++ forum part of the Coders Den category.
11/13/2008, 16:19
|
#1
|
elite*gold: 105
Join Date: Jul 2007
Posts: 737
Received Thanks: 114
|
c++ problem O:
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
|
#2
|
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
|
Doesn't strcmp return zero if the strings are equal?
maybe that's your mistake :-)
|
|
|
11/14/2008, 08:13
|
#3
|
elite*gold: 0
Join Date: Aug 2005
Posts: 443
Received Thanks: 72
|
Quote:
Originally Posted by Bot_interesierter
Doesn't strcmp return zero if the strings are equal?
maybe that's your mistake :-)
|
yep
|
|
|
11/14/2008, 09:19
|
#4
|
elite*gold: 4
Join Date: Aug 2008
Posts: 6,783
Received Thanks: 4,992
|
true, true ;e
|
|
|
11/14/2008, 12:02
|
#5
|
elite*gold: 55
Join Date: Mar 2006
Posts: 4,582
Received Thanks: 1,539
|
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
|
#6
|
elite*gold: 0
Join Date: Nov 2008
Posts: 181
Received Thanks: 465
|
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
|
#7
|
elite*gold: 105
Join Date: Jul 2007
Posts: 737
Received Thanks: 114
|
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
|
#8
|
elite*gold: 20
Join Date: Jun 2005
Posts: 1,013
Received Thanks: 381
|
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
Also reccomend using cout << rather than printf. Not too important though, just don't see why you're mixing C++ stl and C libraries.
|
|
|
Similar Threads
|
Metin 2 Pserver Problem/ Lösung für das Matrix Kartennummer Problem
01/04/2010 - Metin2 Private Server - 3 Replies
Hy Leute
Wie in der Überschrift genannt, hab ich gerade ein Problem mit meinem Metin 2Server.
Ich lasse ihn via Loopbackadapter laufen, funktioniert auch ganz gut.
Ich hab aber jetzt das Poblem, das in meinem Account nur noch Krieger mit Level null stehen.
Wie kann ich das Beheben??, das is auch manchmal da, wenn ich via Navicat n neuen Account mach. Hoffe einer hatt ne Lösung
Hab n Screenshot im Anhang
Aber ich hab ja auch ne Lösung für n anderes Problem.
Gestern hatte ich beim...
|
[Problem] Problem with server starting - cannot find quest index for PaxHeader
12/22/2009 - Metin2 Private Server - 1 Replies
Hello!
I have this same problem as here when i'm starting my server:
http://www.elitepvpers.com/forum/metin2-pserver-di scussions-questions/307143-metin2-serverfiles-ques t-index-fehler.html
But I didn't know the answer.. how to repair this?
Greetings
|
All times are GMT +1. The time now is 17:57.
|
|