Hey there, the problem that I am having is that I'm trying to make a simple scripting language that is coded in notepad, then opens the Engine and it displays the code in a console window.

I am currently stuck at displaying text on the screen, if I enter a sentence
it will only show the first word in. Heres the code:

void say(char *text)
{
std:string say = "";
say += text;
cout << say;
}

    char param1[100];
    char param2[100];
    char param3[100];
    char param4[100];

//------------------------------------------------------------------------------ OPEN THE FILE 

   ifstream myfile ("test.txt");
   if (myfile.is_open())
   {
      while (!myfile.eof())
   {
      myfile.getline(buffer, 100);
      sscanf(buffer, "%s", command);
      realCommand = command;
//------------------------------------------------------------------------------ Begin the script, everything script must have the tag to start.      
      
      if (realCommand == "say")
       {         
           sscanf(buffer, "%*s %s", param1);
           say(param1);
       }

Any ideas, thanks :)

Spaces are treated same as enters, in way they both break strings when using standard string input statements

Ok, what could I do to overcome this problem? Thanks for reply :)

i think there is a command, you can use to avoid those spaces but i cannot recall it at the moment, but it is something about reading to the end of line, just like in files
if i recall il post ;)

Okay thank you :) I'll have a look on the web.

Do you have any ideas how you would change the layout?

For example, at the minute you have to do this to print something:

<script language="myscript">
say this is a cool script

would like it to do:

say ("This is a cool script");

Thank you.

you can use gets(char *string1) function because it ignores whitespaces

didnt get the point of last question
you want to output some text easily? - then use printf ("text text text");

<script language="">


set.background(color) 1f -- sets the background color
set.background(title) welcome to my application

$name; // assigns a string to "name";

say welcome to my first application using my scripting language. Please enter your name.
input (name);

if (name == "Phillip") then 
		       say hello there Phillip! endthen
		       otherwise
		       say Welcome
		       say (name);
 
</script>

Is a basic syntax of the scripting language i'm creating, kinda lol :P

And thanks :) I'll check it out

Unfortunately not all strings are equivalent, and not all string routines work with all strings.

As a general rule I wouldn't use both C style I/O and C++ style I/O in the same program as it can lead to unintended behaviours. That means I would recommend thinking long and hard about using sscanf() in your current program.

I can't tell what type of string buffer, command, and realcommand are because they aren't declared with local scope.

STL string objects can be used as C style null terminated strings if you use the c_str() method.

sscanf() requirs C style strings. Here's the prototype:

int sscanf( const char *buffer, const char *format, ... );

You can't use the == operator on C style strings, but you can with STL strings.

Don't use the return value of eof() to control the performance of a loop body as it will lead to overreading sooner or later. In this case, use one of the input methods:

while(myfile.getline(buffer, 100))

getline() includes whitespace in a string, as long as the whitespace char isn't the delimiting/terminating char.

commented: this man really explains how stuff work and helps +1

Thank you :) Everyone! Btw, totally off the subject but is it possible to integrate other scripting languages into c++ so for example, PHP, Lingo etc?

code integration:

Have a long look at swig http://www.swig.org. I think it is excellent, and have used it with python and lua, and have been very pleased how easy it was.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.