MMOCC the isometric world scene, 2006–now
Archive. Archived from the original MMOCC Forum (2006–2010), recovered from the Internet Archive. The forum is read-only history now — the scene talks on Discord. If you posted here and want something removed, get in touch.

[C Programming]The basics of C!

10 posts · 2008-05-23 · MyBB era
05-23-2008 05:48 AM #1
Hello there,

Now before anyone states, yes I know C is outdated, I know C++ is better. However C is a great language to allow beginners into the world of programming!


Anyway, today I will be showing you guys how to output text in C.

First of all you will need a compiler(DevC++ is great, however any other C compiler will work fine).

Now open Notepad(or DevC++) and type out this little ol' script!

Quote:#include <stdio.h>

int main()
{
printf("Hello, I am outputing some text!");
return(0);
}

Simple yes? Now here is how it works...

Quote:#include <stdio.h> //Includes the header file stdio.h when compiling(This is a bit advanced to explain just now)

int main() //This is is basically defining the "main" function of the program, aswell as defining it as an int function, int meaning integer... meaning whole number :)
{ //Opening bracket
printf("Hello, I am outputing some text!"); //the printf(); function simply outputs text on screen, although it does a heck of a lot more if you continue to learn C
return(0); //The return(); function is basically is what is used to return variables or data outside the main(); function if needed. However we don't need to return anything so we put a 0 between the curly braces
} //Closing bracket

Now go ahead and save that as TEXT.C then use your compiler to convert it into a .exe.


Now if you try to open your program, you will realise that it will open then immediately close. To stop this you will need a little extra code, however you can still view it as it is...

Open up Command Prompt, select Run from the Start Menu and enter cmd.

Now type in cd *:\*(The first * is where you enter your drive letter, normally C. Then enter the route to the folder of where the .exe is saved). Press the Enter key. Now enter text, press the Enter key then watch and be amazed as... some text appears!

This concludes this little tutorial. I hope you learn something from it. Remember C is a great language to start off when you have no experience of programming.


Thanks for reading!
xLite

05-24-2008 02:54 AM #2
Some criticism:

Although return looks like a function and many people use it as such, it's not. It doesn't require the brackets.
You do need to return something (an int, it says it before the main() function name) from the main function (the exit code of the program, normally 0 on success and >0 on failure), and by using return(0) you are returning 0 (success). If you didn't return anything, the compiler would probably show a warning message.

I don't think C is outdated or that C++ is better, but for a beginner, I would recommend a higher level language.

05-24-2008 05:39 AM #3
It is quite a minimal tutorial however I did find it useful, as for high level languages I recommend Python!

PS: Of course C! is greater than C++

05-24-2008 06:20 AM #4
Also you said DevC++ was a compiler, no its an IDE

05-24-2008 06:35 AM #5
I know it is an IDE ^^, but for the sake of this tutorial I called it a compiler to reduce the confusion of the beginners. Otherwise I would of have to explain and IDE in detail to stop the beginners from giving up from confusion . Thanks for pointing that out.

If you guys want more C tuts/more advanced C tuts. Then please say

05-24-2008 07:17 AM #6
This is rather simple. C has it's uses, it's great for writing programs that interact with the hardware, like kernels

05-24-2008 07:41 AM #7
Yeah, good way to put it Adam
I might add variables and input to next tutorial

xLite

05-24-2008 08:10 AM #8
By calling DevC++ is a compiler you are causing more confusion

05-24-2008 08:52 AM #9
Personally I'd recommend something like BASIC to people new to programming to help them get to grasp with the concepts of logical programming. It's like learning to run before you can walk.

05-25-2008 09:59 PM #10
I guess the tutorial is okay for someone trying to grasp the syntax..
I wouldn't recommend Dev-C++ though. It's outdated now. Use an alternative, such as code::blocks.
http://codeblocks.org

Recovered from /printthread.php?tid=6756 · captured 2012.