| View previous topic :: View next topic |
| Author |
Message |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Mar 01, 2008 12:27 pm Post subject: C tut. For noobs |
|
|
Welcome to C tut v 1.0. I made this mainly for reakw0n in his quest to learn C and not use as much delphi.
Part 1: Basics of a C program and Hello World
A C program has a few basic parts. The top section of code will be the declarations, defines, and includes. You have
to decide which headers to use. The code for include is simply
| Code: | | #include <headername.h> |
The header i will be using in this tut is iostream.h. I will also use stdio.h to show you some other functions.
The other main part is the main function. This is the program's entry point. It is main() in most console apps.
To declare a variable in c you use this format
If you want to define the variable right on the spot you would use
| Code: | | type VarName = value |
The most basic program is the "hello CEF program" This is the code
| Code: |
#include <iostream>
int main(){
std::cout << "Hello Cheatengine Forums";
std::cin.get();
std::cin.ignore();
return 0;
}
|
The first thing is including iostream. We include this for the cout and cin functions.
The second piece is entry point main. I make it type int and not void so i can get a return value.
For functions you wrap all of the code in brackets. This shows us the start and end of the function.
To use cout and cin, you have to use the std namespace. There is 2 ways to do this. std::function or after the
include and before main you use
| Code: | | using namespace std; |
I prefer to not use this in a very small program.
when you use cout you have to put << between each new string or variable, like this
| Code: | | std::cout << "hello " << varName << " this is a test and will be on 1 line"; |
i use cin.get() and cin.ignore() to keep the cmd window open. Take out these 2 lines and run the program and you will
see why.
That is the basic Hello World program.
Part 2: printf
One other way of printing text to the console window is to use printf. I prefer to use this because iostream.h is a
huge header and will beef up your program
| Code: |
#include <stdio.h> //this is the header printf is declared in
int main(){
printf("Hello CEF");
return 0;
}
|
This will exit the command prompt quickly because i didn't use cin.get or cin.ignore. You can include iostream and use
these to make it not close quickly.
Part 3: Cin
Cin stands for c input. You can input a variable's value and then do things with it. Like this.
[code]#include <iostream>
using namespace std;
int main(){
int a, b; //declare a & b as ints
cout << "Please input 2 numbers to be added: ";
cin >> a;
cin >> b;
cout << "\n a + b = " << a + b <<" \n"; \n means new line
cin.get();
cin.ignore();
return 0;
}
I will be expanding this almost daily.
~Blankrider
Last edited by HomerSexual on Sat Mar 01, 2008 12:30 pm; edited 1 time in total |
|
| Back to top |
|
 |
.Murder. Grandmaster Cheater
Reputation: 0
Joined: 28 Nov 2007 Posts: 723
|
Posted: Sat Mar 01, 2008 12:28 pm Post subject: |
|
|
Great...
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sat Mar 01, 2008 4:48 pm Post subject: |
|
|
| This isn't C. >_>
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Mar 01, 2008 9:41 pm Post subject: |
|
|
c++ w/e
I dont care xP
|
|
| Back to top |
|
 |
MrNeef Cheater
Reputation: 0
Joined: 26 Feb 2008 Posts: 44
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Mar 01, 2008 10:23 pm Post subject: |
|
|
I dont use the OO aspect of C++(i hate Object Oriented programming) so i consider what i code C. Most of the time i code in straight windows.h.
I call it different because of my views on it.
|
|
| Back to top |
|
 |
systat Advanced Cheater
Reputation: 0
Joined: 15 Feb 2008 Posts: 54
|
Posted: Sun Mar 02, 2008 4:54 am Post subject: |
|
|
| blankrider wrote: | I dont use the OO aspect of C++(i hate Object Oriented programming) so i consider what i code C. Most of the time i code in straight windows.h.
I call it different because of my views on it. |
Jesus...
C++ is all about OOP, using C++ as a C have flaws
You suck, rep -1.
| Code: | | Sorry, but you will have to wait 15038 seconds before you can take rep |
WTF?
_________________
uuuuuuuuuuuuu
Last edited by systat on Sun Mar 02, 2008 6:19 am; edited 1 time in total |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Mar 02, 2008 7:44 am Post subject: |
|
|
are you stupid?
C++ isn't all about OO programming. It's about standardizing and making things easier. I choose not to use OO because i can be more efficient w/o it. Go learn before you say shit dumbass. Not using OO does not have flaws because C++ is not designed just for OO. I'm above your level of programming, i doubt you would see my points.
|
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Thu Mar 27, 2008 9:08 am Post subject: |
|
|
Are you telling me that:
| Code: | #include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
} |
Is simpler and "easier" than:
| Code: | #include < stdio.h>
void main()
{
printf("Hello World");
} |
Seriously. Also... Please don't correct me on void main(). Don't like it, take it up with x0r. =)
Although, I respect you in the fact that you try, unlike most at CEF.
Edit: Wow. This is old.
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Last edited by --Pillboi-- on Thu Mar 27, 2008 4:29 pm; edited 1 time in total |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Mar 27, 2008 11:35 am Post subject: |
|
|
| --Pillboi-- wrote: | | HEY GUYS, CHECK THIS SHIT OUT, I'M A UNIQUE SNOWFLAKE |
face + desk
|
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Thu Mar 27, 2008 4:29 pm Post subject: |
|
|
Unique snowflake? Why do you suddenly, and randomly, have something against me?
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8586 Location: 127.0.0.1
|
Posted: Thu Mar 27, 2008 10:02 pm Post subject: |
|
|
Yay for flaming for stupid topics. Closing this, it's old and dead.
Take your feuds to PMs or your own bandwidth hosted forums.
_________________
- Retired. |
|
| Back to top |
|
 |
|