Jump to content
  • Advertisement
Sign in to follow this  
Xabbu

Function Problem

This topic is 5478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a program that runs a while loop, and if the user enters "test", the function test should run,(which outputs "this is from test"), but nothing happens.What is going on?Heres the code im dealing with:
 while (i = 1)
    {
        
        std::cin>>command;
        if (command == 'test')
        {
                Test();
                
        }
       
    }

Share this post


Link to post
Share on other sites
Advertisement
try this


#include <string.h>

while (i == 1)
{

std::cin>>command;
if ( strcmp( command ,"test") == 0)
{
Test();

}

}



[Edited by - Marcelo Gamba on September 16, 2004 6:08:06 PM]

Share this post


Link to post
Share on other sites
Now im getting this error, which i have no idea what it means.

invalid conversion from `char' to `const char*'

Share this post


Link to post
Share on other sites
The problem is, you've declared "command" as type char, without realizing that that only holds 1 character rather than a string of characters. Declare "command" as a std::string, rather than a char.

Share this post


Link to post
Share on other sites
i think the problem lies with your condition in the while (blah)

while (i = 1)

try while (i == 1)

since '=' is the assignment operator, which assigns the right hand value to the laft hand variable.

and '==' being the equality operator.

hopefully somewhere in your code you have something that sets i to something other than 1, otherwise, since i is always 1, it will get stuck in an infinite loop. which isnt nice

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!