FireNet 64 Posting Whiz in Training

hey,here a simple way to see which of 2 strings is greater :)

int str_alp(char *s1,char *s2)
{
    if(strcmp(s1,s2)==0)return(0);   //if they are equal

        for(int i=0;s1[i]!=0;i++)
        {
              if(s1[i] > s2[i])return(1);
              else if(s1[i] < s2[i])return(2);
        }

    return (2);  //hey if they are not equal and s1 not greater than s2 then s2 is greater
}

See if you can use it

FireNet 64 Posting Whiz in Training

Here is the server made by Aaron Anderson (to him is this tutorial dedicated) exactly how it was sent to me.Compare it with your code.

I would like to add the Anderson has an excellent coding style and great
potential as a coder.He is dedicated to his work and very through.I wish
him very best.This server is done very well and is no copy paste job.

/*

// COMMENTS //

	Author	:	xmen90s -> based on the tutorial of Aaron aka FireNet
				[email]xmen90s@yahoo.com[/email]

	Date	:	June 10th of 2004

	Purpose	:	This server receives input from multiple clients and keeps
				a RAM database of a few pieces of information like screen
				name, character model, and position
				The server then will echo back information to all clients
				instructing them on where to move actors

				Essentially I'm working on rebuilding the multiplayer system
				of a game called Dungeon Siege from ground up.

	I want to put a special thanks out to Aaron aka FireNet for writing
	the most excellent tutorial I have ever read.  I went from knowing
	cin and cout to writing a full non-blocking multi-client echo server
	in just one and a half weeks because of him.

// LINKS //

	Remember to link to : wsock32.lib

*/

// INCLUDE FILES //

#include <fstream.h>
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <winsock.h>

// DEFINITIONS //

#define		PORT 4000		// Define the port to connect to
#define		MAX_CLIENTS 10	// Define the maximum number of clients we can …
FireNet 64 Posting Whiz in Training
Creating Servers for handling Multiple clients
                              Fog Edition
			       By FireNet

(This document is dedicated to my friend Aaron Anderson)

(Fog Edition means I dont tell you everything stright.All the info will be there but you will have to do much thinking)

Servers and Clients,the backbone of the internet after the TCP/IP protocol.Right now I will go
yak yak on TCP/IP so if you know it skip this.Also I intend not to provide you with everything.
I will provide enought material and directions for you but you will have to do something on your
own.I just teach you how to setup a basic server which can accept multiple connection and
of course guidlines on how to make a robust server.We will also look into a very simple kind of
server 'Chat servers'.

TCP/IP
-------
TCP stands for Transmission Control Protocol.IP stands for Internet Protocol Address.TCP
implementations provides a defined way about how data transmissions can be done over
the wire between diffrent computers.There are a few sub protocols but we wont worry about
them since they are at a lower level.

OSI Model
----------
It is an open standard published by the ISO(International Standards Organisation) on how
systems can recive and transmit data with each other.TCP/IP is an implemetation of it.
It has 7 layers and each do a diffrent job.We dont want to go into details now.

This helps various …

FireNet 64 Posting Whiz in Training

hey,I will give you a direction.

You will first have to make a funtion which will compare 2 strings and say which one is greater by comparing the individual chars and returning when it hit's a char which is no equal to the other, like sad sam, (in this case m > d).

Put this into a sort algorithm.

[think this is not much help eh?,see what you can do and you might even suprise yourself.Sometimes just a direction can do wonders.If you still have problems post here,maybe with what you have coded and we will check it out.your will learn more if you do it yourself :cool: :cool: ]

FireNet 64 Posting Whiz in Training

Yea there are a lot of free compilers.

http://www.borland.com/
http://www.delorie.com/djgpp/
http://www.bloodshed.net/devcpp.html

I would recommend Borland.If you get linux there a compiler with usually.
http://cplus.about.com/library/weekly/aa031502a.htm
http://www.scintilla.org/

If you dont had a connection above or equal to ADSL then dont try downloading any big distros.Since you are new to linux: linux does not come in a zip file.It is spread across multiple files and some are huge (eg RedHat 650 mb).

Buy a cd, it's the best if you are a newbie as you will never be able to install a package from the web without knowing a lot.The red hat site has a lot in way of docs.

You will need to partition your harddrive.Partion Magic is good.

http://www.redhat.com/
http://www.suse.com/us/
http://www.mandrake.com/

Now there are some altra small linuxes(with out fancy graphics of course)
http://www.ibiblio.org/pub/linux/distributions/baslinux/

Check this out
http://www.linuxlinks.com/Distributions/Floppy/

FireNet 64 Posting Whiz in Training

maybe you should try tinkering with the compiler options

or try including both winuser.h and stdafx.h

FireNet 64 Posting Whiz in Training
FireNet 64 Posting Whiz in Training

Tell me where my beans are!!!!!
Tell me where my beans are!!!!!
Tell me where my beans are!!!!!
Tell me where my beans are!!!!!
Tell me where my beans are!!!!!

Make sense,no?post with more info next time jennie

FireNet 64 Posting Whiz in Training

How am I supposed to know what you can do?(Just kidding)

Yes you can in C, C++ and ASM.(ok some other languages also).Do a few searches on http://www.google.com/
You will find something.

Slade commented: couldn't have given a better answer, idiots need to search google first +36
FireNet 64 Posting Whiz in Training

Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(

FireNet 64 Posting Whiz in Training

yea,change you nick.It's hard to think of a number as a human you know.

New to the internet?I agree with kc0arf it is a very bad idea to let your details float around.People can/will put it to misuse(especially on the internet[Take it from a guy who has gone real deep into security]).

FireNet 64 Posting Whiz in Training

@cscgal
go to bed earlier!

Yea you should.Leave lights on at night if you are using the comp

FireNet 64 Posting Whiz in Training

You also forgot the ; after all of the const's in your program.
Christian

You also forgot the ; after your funtion declarations

What ever you do in C++ all line have to end with a ; except in a few cases like loops,if elses etc.

FireNet 64 Posting Whiz in Training

Not really.
If you are using a header with a static library you should try getting the latest version of the static library.

Otherwise if you have link errors is you own programs it maybe because you declared a funtion and forgot to define it.Check for these and fix them.

Link error occur when the linker cant find the modules(funtions,externs) the compiler reffers.

FireNet 64 Posting Whiz in Training

You are most welcome.Now there is a full tut on file i/o in the C++ tutorial section :-)

FireNet 64 Posting Whiz in Training

Now here's a printer friendly version(has a few fixes to part I)

http://www.polarhome.com:793/~xlock/txt/fstream.txt

FireNet 64 Posting Whiz in Training

You could use GetTickCount().

double next_time  = GetTickCount();

while (true)
{
       if(GetTickCount() >=next_time + 100)
       {
             cout<<"Bong\n";
             next_time  = GetTickCount();
       }
}
FireNet 64 Posting Whiz in Training
File I/O
With C++ Fstream

Intro

File handling is as simple as writing in a book, much easier to modify and
find. It's so simple people get confused with it :-). Welcome to the world of file handling.

We will use the c++ fstream classes to do our file handling. So, what is a file? A file is just a bunch of bytes stored on a hardisk. Some have a specific structure others dont. Files are used to save info so that it can be retrived later for use. [I dont think you will want to save 100 people's address in memory will you].

Types of Files

Actually there are only two. Text files and binary files. In text files data is stored as readable chars and binary file are in machine language. So if you output abc123 to a text file you will see abc123 but in a binary file you may see only a bunch of black blocks if you use notepad. The binary files are smaller in size.

Fstream.h

fstream.h provides simultaneous input and output through ifstream, ofstream and fstream.

ifstream       - open the file for input
ofstream       - open the file for output
fstream       - open the file for input/output/both

Writing to a file

Relatively very simple.

Steps:

  • Declare an ofstream var.
  • Open a file with it.
  • Write to the file (there are a couple of ways.)
  • Close it.

Eg Program 1.1

#include <fstream.h>

void main
{
    ofstream file;

    file.open("file.txt");      //open a file …
N3wbi3C0d3r commented: GREAT JOB, KEEP EM COMIN +1
sharunkumar commented: Thanks a lot! Really needed something like this! :D +0
FireNet 64 Posting Whiz in Training

Oh, my poor child :-),
[just kidding].
If you have an array like array[3] you can use only 3 elements i.e
1. array[0]
2. array[1]
3. array[2]

If you go beyound that you will get errors as you would be writing over memory used by some other program.

so array[3] is the fouth element.so declare it as int array[4].Should solve you prob

FireNet 64 Posting Whiz in Training

http://www.scintilla.org

A multi-lingual editor and really lite.It's fully customisable by editing property files like a script file.Very useful for some one who works with multiple languages all the time.

Some langs it supports:C/C++,Java,PHP,Perl,VBscript,Python yea right a lot more :-)

FireNet 64 Posting Whiz in Training

Not neccesarly,it may be better in most cases to begin with classes.Of course you make structs in classes but with experiance you will be able to write classes directly.

FireNet 64 Posting Whiz in Training

ya know marceta right,if you dont think for your self you will never really progress.Knowledge is diffrent from wisdom.If you cant process the knowledge you have you will be really nothing more than a hardisk.Learn and remember this.

Advice:
Never put i/o in classes.Use other funtions for that and call the construtor with parameter.Better yet use contructors only to assign default values to the variable and use a funtion like init() to initialise the variables.

This would sure enhance the re usability of your code.(I agree with you teacher)

FireNet 64 Posting Whiz in Training

I dont know Russian sorry :-))

FireNet 64 Posting Whiz in Training

This is not neccessarily true! You can make decent text based RPGS (many games for that matter) in a single file using structures only, not classes! PM me for a source code of a pretty cool basic game if you want creator of thread.

later

I did not say anything about games, but in C++ it's best if you know classes along with file i/o because it simpilfies a lot of things.And they are the basics of C++.

Now structures and classes are complimentary it's really your choice most of the time.But usally if you have experiance using classes, for games many classes will be used.

FireNet 64 Posting Whiz in Training

Hello guys,
is there a way to declare global variables as [B]float[/B] and then convert them to [B]int[/B] to be used in a function? i.e.

yea,sure thing use type casting.

Eg:

float x = 9.879;
int y = (int)x;         //y will be  9

you can do it the other way around too.
x=(float)y;

Usually float and int can be assigned to each other as C++ normally does that type casting automatically

FireNet 64 Posting Whiz in Training

Yea search buddy you will learn a lot .best of luck

FireNet 64 Posting Whiz in Training

My God I even had a comp science teacher ask me this.Arrrg one will go mad.

It's simple.Cut a few funtions out of you code and paste them in a file with a .h extension and call #include "your_header_name.h" to include that.

Note: not < > but " " if it's in the current directory else you have to supply the full or relative path.

All the rules are same as normal C++ syntax.

----------------------------------------------
That was very simple thing.Headers can be used for more things.They can just contain funtions declarations without definitions.In that case it will be used to link to a static library.

Eg.Make a header file with 2 funtion declarations like fun1(); fun2(); only
Include it with a cpp file and call the funtions and compile.

You will get no errors on compile but on linking you will see an error similar to the following:

undefined module fun1() refferenced from Module main.cpp
undefined module fun2() refferenced from Module main.cpp

I hope you understand a header in not really diffrent from a cpp file.Btw you can also include .cpp files.

Eg: #include "wow.cpp"

FireNet 64 Posting Whiz in Training

Good, well next time try doing the checking first Ok

FireNet 64 Posting Whiz in Training

i tried it that way, but it came out with more error messages, that's why i change it to this one, 'cause this way it show less error messages.

Post some error messages will you,what you said is just like 'if you dont know why I am angry with you then I am not gona tell you'

FireNet 64 Posting Whiz in Training

Dir.h is probably what you want if you use C++

int chdir(char *path);

use it like chdir("c:\windows");

FireNet 64 Posting Whiz in Training

Found the solution:
GetModuleFileName() ;

First module is always the current process, includes path and various other details.

What are the parameters or returns ??

FireNet 64 Posting Whiz in Training
FireNet 64 Posting Whiz in Training

You can also use conio.h.Check my post below.It should give enough info I think.

http://www.daniweb.com/techtalkforums/showthread.php?p=30122#post30122

FireNet 64 Posting Whiz in Training

You mean to the paper or the screen.

if you want on the screen use conio.h

Colors
------

0    BLACK          /* dark colors */
1    BLUE
2    GREEN
3    CYAN
4    RED
5    MAGENTA
6    BROWN
7    LIGHTGRAY

8     DARKGRAY       /* light colors */
9     LIGHTBLUE
10    LIGHTGREEN
11    LIGHTCYAN
12    LIGHTRED
13    LIGHTMAGENTA
14    YELLOW
15    WHITE

1.textbackground(int) to change the background color
2.textcolor(int) to change text color

Now you can call any to the above funtions as below:
textcolor(2); //green color
textcolor(BLUE); //blue text color( see the above list for more colors)

in C++ sometimes you will have to call clrscr() to clear the screen before the changes will become visible.

if you call clreol() [clear till end of line] only that line will be affected.Then when new text is typed on the next line sometimes the changes will remain other wise the old settings.

This varies from complier to compiler.I have no idea why.

gotoxy(int x,int y); //shift text cursor location, starts at 1,1

Helps ? :!: :idea:

FireNet 64 Posting Whiz in Training

Yup, C++ is the best to start out of the langs you mentioned. try www.google.com and search for tutorials.

If you have no experiance what so ever QBASIC is also somewhere to start.

For C++ you will need a complier and the best free easy one for a new user would be DevC++

www.bloodshed.net/dev/devcpp.html

FireNet 64 Posting Whiz in Training

Are you using ShellExecute() ??

FireNet 64 Posting Whiz in Training

Now this is something which depends on you.If you want you can store all the dll in some specific folder and when the program is launced open those file with the absolute paths.

If your program is DOS the you can look in argv[0] for the full path.
eg.c:\sdd\path\yourprogram.exe is what is there.

int main(int arg,char **argv)
{
       cout<<argv[0];
       return 0;
}

yea there are some standard headers which provide funtions to splitup the path into various componets but if need them tell me and i will look it up

FireNet 64 Posting Whiz in Training

char chr = 'a';

cout<<chr; //will show the char
cout<<(int)chr; //will show the ancii code

chr = 232;

cout<<chr; //will show what ever 232 repesents
cout<<(int)chr; //will show the ancii code i.e 232

FireNet 64 Posting Whiz in Training

http://xlock.ssr.be/

is my site,so when it's up you will get the tut or an admin will have to put up a sticky of the file i/o tut

FireNet 64 Posting Whiz in Training

Also add what your program is supposed to do(a general idea) and put the compiler out put in [ c o d e ]

FireNet 64 Posting Whiz in Training

I would suggesst you first learn structures,classes and file i/o before trying games.You will just be frustrated and end up failing if you jump into games too soo.

Try www.google.com and search for c++ tutorials.

FireNet 64 Posting Whiz in Training

Dump the fox-whatever.There are alot of such stuff which have no future. Get rid of Bloodshed also.I have used it and some standards are not supported.Borland Command line complier (they give that for free) is much
better.

Window's native GUI implement (API) is also good to know it's not so tough.

FireNet 64 Posting Whiz in Training

Your most welcome,if you keep going fstream will be as easy as cout and cin
Well have fun buddy.Oh read up someting more on fstream file modes
(like ios::in and some more) and also file checking funtions (like file.good()).
The will be great for good database management and for proper error checking.
[I would recommend the above because it would be a feather in you cap
if you know that stuff.It will save a lot of time during development and
add good polish to your programs] :cool: :lol:

FireNet 64 Posting Whiz in Training

Guys and gals just dont seem to understand file handling
Check this link http://www.daniweb.com/techtalkforums/thread5720.html

I give a basic intro on how to use a database.It's just the steps you can follow to retrive or write data.I use structs but you can also uses classes(Hey calsses are just structures with funtions attached,so you can write them to a file).

Many seem to have a problem with file handling and databse.[Does anybody want a full blown tutorial on fstream file handling and databses in C++,i will do one if ya want]

FireNet 64 Posting Whiz in Training

No way,
I not talking of loading dll like funtionality.These plugins I am talking of are semi - autonomous i.e they are in no way related to the main server.

Imagine a market place made up of different sellers.The server is the market place and the plugins are the sellers.These sellers are seperate but a part of the market.

These plugins are not seperate programs run like apache (like php,i know apahce i use it to test my site before i put up on my computer).These are compiled along with the main server.

The clients will only connect to the main server.The main server will the allow the client to choose a plugin to use (the should also be able to switch afterwards).

These plugins should then be able to provide some service like mail,bbs etc. or be a proxy server or a protocol translator which connects to other server and get data and then passes it to the client.

The main server should then be able to handle multiple clients.The main server should also have multiple plugins(that i talk of).Then these multiple seperate clients should all be able to interact with the same plugins or diffrent plugins at the same time and the plugins should be able to provide both types of services I mentioned before.The main server should be able to handle it all togather without any major delay.

Yea in windows without multiple threads and only one connection reciving port.

FireNet 64 Posting Whiz in Training

How many of you guys belive it is possible to program a server and create within it a simple environment in which people can write their own pieces of code and complie it without problems.

This server should be capable of using multiple 'plugins'(the pieces to code which others write and is complied with the main server).These plugins should be able to connect to other servers or be able to provide any other service(not remote).

The main server should be able to loop through all this(remember the so called plugins are compiled into the server) i.e the muliple 'plugins' running at the same time while accepting connections and commands from multiple clients

Would this be possible,immpossible,crazy,never gona work,only a genius can make one,no one will ever??????????

FireNet 64 Posting Whiz in Training

I changed my website address to http://www.xlock.ssr.be/ go there if you want the latest stuff.I wont bother with cjb.net any more

FireNet 64 Posting Whiz in Training

I am currently developing a Snake game with multiplayer support(Not Network based) with unlimited no of players(ok limited by the keys and RAM and processor speed but not restricted).

I developed a nice concept of key maps to load all controller information into memory and handle it there.This works just fine.

Right now it's on version 0.5a and you can get it at http://www.xlock.cjb.net
I still hav not added the configuration editor so you can only use 2 player and single player.Try it out,it does not crash or cause problems.I just need help to improve it's memory mangement.

The game works just fine with proper speed and all but it crashes with an abnormal termination error if I use fstream.It also will quit if i use new to allocate memory for the snake(the blocks).
Both are only a problem if is use them after i enter mode 13.

The current work around is loading all the needed memory into a linked list and popping it when it is required.This is quite a waste.And linmits the max score you can get.

I use Borland C++ 5.02.I complie the exe with DOS(Standard) and Huge Memory Mode,with Class Library and Floating Point Support.

Currently I load all the key maps into memory before entring mode 13.

Needs
~~~~
1.A safe way to read data from a file after entring mode 13 <very important>
2.Use dynamic memory allotement after entring …

FireNet 64 Posting Whiz in Training

I do not not understand how the pipeing program works

FireNet 64 Posting Whiz in Training

Use string.h

strcmp(str1,str2);

returns 0 if they are equal