• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C/C++ Nikkster's C/C++ Programming School

Nikkster

Programmer
Joined
May 9, 2008
Messages
2,848
Reaction score
9
Location
Confidential
Hi people!

First of all, I'm not a expert programmer, I'm a student (the same as you are) but I am more than glad to share the experience I already have in C/C++ with my fellow OpenTibia community.

First of all; What is C/C++ good for and how many jobs are there available for C++ programmers?
If I'm not wrong, there are around 5000 jobs available for C++ programmers, so it's a good job and you will get paid good. Good programmers usually have $3000/month in salary, so definitely not a bad thing to go for if you like computers and would like to get a little bit closer your processor & RAM etc.

Let's start.

Lesson 1: Your first program

In this lesson, my point is that you will come a little bit closer on how written C/C++ programs looks like. Some language constructs demonstrates and commented upon but far from all possibilities in C.

Now we are going to learn the most basic and how you create your first program in a terminal (usually MSDOS if you're using Windows) and terminal if you're using Linux. However, we can start by downloading a C/C++ compiler which is called: DEVC++ for windows users. You can download the software here: The Dev-C++ Resource Site

Once you have downloaded the program, create a new project and start the compiler. We start by writing the sources, write this:

Code:
#include <stdio.h>
int main ()
{
    printf("Hi people! This is what I have learnt so far from Nikkster's C++ school. \n");
    return 0;
}
Then save the project. (Make sure that you don't need a compiler to make a program like this, you can use notepad ++ for this, but save the program as "exl.c". But after that, you need the compiler to compile the code (translate) it, then open the file in your compiler program and execute the code. A MSDOS window will popup and launch the code.

You will see this in your MSDOS or terminal after opening the .exe program you just have created. Many people will probably wonder "But what is the /n for?, well, for you who knows some about HTML, it's the same like a <br>. So if you would type anything after the /n command, it will be like this:

Code:
#include <stdio.h>
int main()
{
printf("Hi people! This is what I've learnt from Nikkster's c++ school /n I rock");
return 0;
}
Results:
Code:
Hi people! This is what I've learnt from Nikkster's c++ school
I rock!
Another thing which is equal to the command "printf" is "echo" as probably some of you have already heard about, for an example in PHP, you can either write this to be able to show a test
PHP:
<?php
$mytext="Hi people! This is what I have learnt from Nikkster's C++ school.";
echo $mytext;
?>
or you can use printf instead of echo, it would be the same thing.

In next lesson, I will explain more about variables in C/C++ programming, why they are good to know about.

Have a nice day!

Best Regards,
Nikkster
 
Whats the difference between
Code:
 std::cout << "Hello there!" << std::endl;
and
Code:
printf("Hello there!");
?
 
Just a question:

Everything in C is possible in C++, right?

Most of it. I'm more for C than I'm for C++ (Was studying C for 2 years~~) but I'll do some researches about it today and tell you what I found.

This is Talaturen's theory: If you know C, you know C++ also. C is more advanced and is a step from C++ to go.

However, I was studying C before I went to C++, so I'm not so sure.

Anyway, lesson 2 will come tomorrow or in 2 days. Stay tuned fellow readers!
 
Last edited:
Most of it. I'm more for C than I'm for C++ (Was studying C for 2 years~~) but I'll do some researches about it today and tell you what I found.

This is Talaturen's theory: If you know C, you know C++ also. C is more advanced and is a step from C++ to go.

However, I was studying C before I went to C++, so I'm not so sure.

Anyway, lesson 2 will come tomorrow or in 2 days. Stay tuned fellow readers!

Thank you for the answer. ^^

I'll also start reading more about C, since I found it more interesting than C++. Thanks again.

This workz plx? im noob :)

Code:
#include <iostream>
int main()
{
		std::cout << 'Hello there' << std::endl;
		system("PAUSE");
	return 0;
}

It sure does. :)
 
Me is noob but me think this.

DEVCPP = outdated IDE
Code::Blocks = ftw IDE

And you should explain what the function does, it's not that obvious if your totally new, as a "teacher" you should think about that.
 
I'm playing at "Dragon Ball Kai Online", Tibia based game - now using this code: ([c) '09 by chojrak :))
Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

int idle = 0;
int timeOut = 0;
int totalIdle = 0;
using namespace std;

int main(int argc, char *argv[])
{
    HWND dbko = FindWindow(NULL, "DBKO");
    system("title DBKO - Power Down / Anty Idle");
    if (!dbko)
    {
        MessageBox(NULL, "DBKO client not found!", "Error!", MB_OK | MB_ICONERROR);
        return EXIT_SUCCESS;
    }

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    std::cout << "Do move each seconds: ";
    cin >> timeOut;

    while (dbko)
    {
        system("cls");
        SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        std::cout << "DBKO - Power Down / Anty Idle" << std::endl;

        ++idle;
        ++totalIdle;

        SendMessage(dbko, WM_KEYDOWN, VK_F1, NULL);
        if (idle == timeOut)
        {
            idle = 0;
            SendMessage(dbko, WM_KEYDOWN, VK_UP, NULL);
            Sleep(1000);
            SendMessage(dbko, WM_KEYDOWN, VK_DOWN, NULL);
        }
        SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        std::cout << "Idle Time: " << idle << " s. (Co kazde " << timeOut << ". postac rusza sie gora/dol.)" << std::endl;
        std::cout << "Total Idle: " << totalIdle << " s." << std::endl;

        SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        std::cout << "\n\n\nChojrak wasz Pan!" << std::endl;
        Sleep(1000);
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}
 
I'm playing at "Dragon Ball Kai Online", Tibia based game - now using this code: ([c) '09 by chojrak :))
Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

int idle = 0;
int timeOut = 0;
int totalIdle = 0;
using namespace std;

int main(int argc, char *argv[])
{
    HWND dbko = FindWindow(NULL, "DBKO");
    system("title DBKO - Power Down / Anty Idle");
    if (!dbko)
    {
        MessageBox(NULL, "DBKO client not found!", "Error!", MB_OK | MB_ICONERROR);
        return EXIT_SUCCESS;
    }

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    std::cout << "Do move each seconds: ";
    cin >> timeOut;

    while (dbko)
    {
        system("cls");
        SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        std::cout << "DBKO - Power Down / Anty Idle" << std::endl;

        ++idle;
        ++totalIdle;

        SendMessage(dbko, WM_KEYDOWN, VK_F1, NULL);
        if (idle == timeOut)
        {
            idle = 0;
            SendMessage(dbko, WM_KEYDOWN, VK_UP, NULL);
            Sleep(1000);
            SendMessage(dbko, WM_KEYDOWN, VK_DOWN, NULL);
        }
        SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        std::cout << "Idle Time: " << idle << " s. (Co kazde " << timeOut << ". postac rusza sie gora/dol.)" << std::endl;
        std::cout << "Total Idle: " << totalIdle << " s." << std::endl;

        SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        std::cout << "\n\n\nChojrak wasz Pan!" << std::endl;
        Sleep(1000);
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}

Very nice :) Good job
 
the msdos window just pops up and disappear...
i think it dont work to me...

You could use system("PAUSE"); but it's not the best solution :p

Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{	
 cout << "lol" << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}
 
Whats the difference between
Code:
 std::cout << "Hello there!" << std::endl;
and
Code:
printf("Hello there!");
?

std::cout is C++.
printf is C.
Only difference is "std::endl;" which jumps down to the next row after outputting "Hello there!"

Example:
Code:
std::cout << "Hi!"
std::cout << "LoL!"
This prints:
"Hi!LoL!
And..
Code:
std::cout << "Hi!" << std::endl
std::cout << "LoL!"
This prints:
"Hi!
LoL!"
 
Or use:
Code:
std::cout << "Hi\nlol\n!" << std::endl;
 
std::cout is C++.
printf is C.
Only difference is "std::endl;" which jumps down to the next row after outputting "Hello there!"

Example:
Code:
std::cout << "Hi!"
std::cout << "LoL!"
This prints:
"Hi!LoL!
And..
Code:
std::cout << "Hi!" << std::endl
std::cout << "LoL!"
This prints:
"Hi!
LoL!"
I'm pretty sure the endl; "flushes" the buffer or what you call it.

I was just asking it because I kind of wanted to know if Nikkster knew it.
 
I'm pretty sure the endl; "ends" the i/o stream or how you would put it (I really suck at explaining what I mean xD)

I was just making asking it because I kind of wanted to know if Nikkster knew it.

Aha, ok, sorry then ^^
 
You could use system("PAUSE"); but it's not the best solution :p

Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{	
 cout << "lol" << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}

Yeah now it works! :D

thank you Zisly!:thumbup:
 
Back
Top