![]() |
|||||
|---|---|---|---|---|---|
| Home | Products | Support | Services | Shop | Company |
Products >lcc-win32 > Tutorial
This tutorial is meant as a short introduction to using Lcc-Win32 / WEdit programming environment. No previous knowledge of WEdit or C programming is neccessary, although you should be familiar with using Microsoft Windows programs at user level.
Also available:
Every decent programming tutorial starts with a simple program, that prints "Hello World" to the screen. We're not going to make an exception, so here we go:
As you probably know, every C program consists of a number of source files and other definition files which are used by compiler and linker to make an executable program. As there can be a lot of source files (several hundreds or thousands in large projects) that contain many mutual dependencies and links, compiler must be instructed which source files should be compiled, which dependencies they contain, how the resulting executable should be named etc. This information is usually stored in a file called Makefile. Makefiles have a very strict syntax and can get pretty complicated (in large software companies, there are people who just write makefiles!) and that's why WEdit offers a more intuitive way of keeping all the information neccessary to make your program.
Every time you start writing a program in LCC-Win32, you create a new project. After you've done that, you add files to the project, modify application properties and you can even use a version control system, that helps you track you changes to the project in time and work in team on the same project.
Click on Project menu, then Create ... option.
You'll be asked for the name of project.
Enter hello
Wedit now needs to know, where your source code files will reside (Working directory) and where the object files and executable should be placed (Output directory).
Use Browse button to pick a directory of your choice.
Leave other options as they are. You may notice that type of project is set to 'Console Application'. In Windows, there are basically two kinds of user programs
- console applications, that run in a text window (also known as dos box)
- GUI applications, that use windows, menus and other visual elements as
their user interface.
Our first program will be a console application.
Click on Create
WEdit can create a basic application skeleton for you, so that you don't have to write it manually every time you start a new project. In our simple console application WEdit will create source file hello.c and put some useful code in it.
Click on Yes
Next dialog allows to modify other projects properties. We do not have to change anything for our project.
Click on OK
As the last part of the new project definition, you see Compiler/Linker/Debugger settings dialogs. You do not have to change anything for your 'Hello World' project.
Click on Next buttons and on the Finish button on the last page.
Now you see contents of file hello.c, which was generated by the application skeleton feature of WEdit.
If you already know something about C programming, you'll quickly see that upon execution, program looks for number of command line arguments it was invoked with. If no arguments were given, it will call function
void Usage(char *programName)
And this is where we will place our code to display string Hello World.
Replace function call (on line 7)
fprintf(stderr,"%s usage:\n",programName);
with
fprintf(stderr,"\n\nHello World!\n\n");
Hint: In the lower-right corner of application window you see function name, line and column on the current cursor position.
Note: The '\n' sequence is C formatting token for new line. Our program will thus print two new lines, then text Hello World, and again two new lines.
Now it's time to make the executable code of our program.
Click on Compiler / Make.
WEdit shows the list of files that were modified and offers to save them. If you don't save the files, the program will get compiled with the old status of the file. you've made.
Click on Save all
A frame in the lower side of WEdit window pops up and informs you of compilation status.
Hint: On the lower-left side of WEdit window you see three
small buttons:
You
can use them to show/hide build status window.
Now you're ready to run your program.
Click on Compiler / Execute hello.exe
And here's how the result should look like:
Congratulations! You've successfully compiled your very own Hello World application!
© Q-Software Solutions GmbH
1999-2010
Terms and
Conditions