Saturday, September 20, 2008
learnings of the week
CONDITIONAL STATEMENT
Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.
Types of conditional statements:
The If Statement
The If-Else Statement
The Nested-If Statement
The If-Else-If Ladder
The Switch Statement
The Nested Switch Statement
The If Statement
Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
Statement may either be a single C statement or a block of C statements.
The If-Else Statement
If an if-else statement, if the expression is TRUE (1), the statement or block of statement after the if statement will be executed; otherwise, the statement or block of statement in the else statement will be executed.
Note: Only the code associated with the if or the code that is associated with the else executes, never both.
The Nested-If Statement
One of the most confusing aspects of the if statement in any programming language is nested ifs. A nested if is an if statement that is the object of either an if or else.
This is sometimes referred to as “an if within an if.”
The reason that nested ifs are so confusing is that it can be difficult to know what else associates with what if.
Fortunately, C provides a very simple rule for resolving this type of situation.
In C, the else is linked to the closest preceding if that does not already have an else statement associated with it.
Note that there is a pair of braces found in number 2 and number 4.
The pair of braces defined the scope of the if statement in number 1 starting from the { in number 2 and ends with } in number 4.
Therefore, the else statement in number 5 cannot paired with the if statement in number 3 because the else statement is outside the scope of the first if statement.
This makes the if statement in number 1 the nearest if statement to the else statement in number 5.
The If-Else-If Ladder
In an if-else-if ladder statement, the expression is evaluated from the top downward.
As soon as a true condition is found, the statement associated with it is executed and the rest of the ladder will not be executed. If none of the condition is true, the final else is executed.
The Switch Statement
The switch statement is a multiple-branch decision statement.
In a switch statement, a variable is successively tested against a list or integer or character constants.
If a match is found, a statement or block of statement is executed.
The default part of the switch is executed if no matches are found.
According to Herbert Schildt (1992), there are three important things to know about switch statements:
1. The switch differs from if statements in such a way that switch can only test fro equality whereas if can evaluate a relational or logical expression.
2. No two case constants in the same switch can have identical values. Of course, a switch statement enclosed by an outer switch may have case constant that are the same.
3. If character constants are used in the switch, they are automatically converted to their integer values.
Note: The break statement is used to terminate the statement associated with each case constant. It is a C keyword which means that at that point of execution, you should jump to the end of the switch statement by the symbol }.
The Nested Switch Statement
CONDITIONAL LEARNINGS..hhhmmm
This week we learned about the types of conditional statements, how to use it and its general forms.
First, we have to know what a conditional statement really is.
Conditional statement is used for decision-making. It performs an action depending on whether or not a condition is true. If the condition is true, the statements following the condition are executed. But if the condition returns false, it will disregard the enclosed actions and continue to the next statement that follows the condition block.
TYPES OF CONDITIONAL STATEMENTS
- THE IF STATEMENT
- THE IF ELSE STATEMENT
- THE NESTED IF STATEMENT
- THE IF ELSE IF LADDER
- THE SWITCH STATEMENT
- THE NESTED SWITCH STATEMENT
THE IF STATEMENT
The if statement is a simple decision-making statement that is used to execute a statement or a group of statements based on some condition. If a condition is true, the statement in the if block is executed; otherwise, the statement following the if block is executed.
General form
if(condition)
{
statements
}
THE IF ELSE STATEMENT
The if-else statement is used to execute a statement or a group of statements based on some condition. If the condition is true, the statement in the if block is executed. If the condition is false, the statement in the else block is executed.
General form
If(condition)
{
statements
}
else
{
statements
}
THE NESTED IF STATEMENT
One of the most confusing aspects of the statement in any programming language is nested ifs. A nested if is an if statement that is the object of either an if or else. This is sometimes referred to as “an if with an if”.
THE IF ELSE IF LADDER
The if-else if statement is used to check several conditions. If any of the condition is true, the statement of that block is executed; otherwise, the value in the else block is executed.
General form
if(condition)
{
statements
}
else if(condition)
{
statements
}
else if(condition)
{
statements
}
else
{
statements
}
THE SWITCH STATEMENT
The switch statement is a multiple-branch decision statement. In a switch statement, a variable is successively tested against a list or integer or character constant.
If a match is found, a statement or block is executed.
General form
{ Case constant: ; break; case constant: ; break; default: ; break;}
THE NESTED SWITCH STATEMENT
General form
switch(variable)
{ case constant:{ switch(variable) { case constant: statement sequence break; case constant: statement sequence; break; } break; } case constant: statement sequence; break; default: statement sequence;}
Friday, September 19, 2008
What's With...?!!!
TurboC in a nutshell
TurboC is a linkable library and a set of C header files that make it easier to port C code originally written for Borland's MS-DOS based Turbo C compiler to GNU gcc -- and therefore to a wide variety of *nix computer platforms. Generally speaking, it is the following:- An implementation via ncurses of conio.h from Turbo C.
- An implementation via Xlib of graphics.h from Turbo C.
- A few other functions and time-saving features thrown in for convenience.
- A means of overcoming the integer datatype discrepancies between Turbo C and GNU gcc.
Why was TurboC created?
I have written quite a lot of MS-DOS based software using Borland's Turbo C 2.0 compiler. When the inclination finally hit me to make some of this otherwise-deceased code available as free software, my first innocent idea was to release it under the GPL, simply labeling it honestly as MS-DOS code, and then later to port the code to *nix as time and interest permitted. It was obvious that directly porting to *nix up-front would be a time-consuming task.But I ran into a snag. It's no good to release software if there's no way for anybody to find out about it. My preferred channel for announcing open-source software is freshmeat, but freshmeat doesn't "do" MS-DOS (and therefore politely declined to accept my MS-DOS projects).
Apparently, necessity really is the mother of invention. It occurred to me that if I could provide appropriate Turbo C compatible libraries and header files, then the effort of porting Turbo C code to *nix would be greatly simplified. In other words, it would be relatively easy to provide *nix versions of the old MS-DOS code. Whether it's absolutely easy or not depends a lot on the program you're trying to port.
Alternate Approaches
For conio.h functionality, you might consider Pablo Vidal's UConio library instead. I've not used it, and don't know its advantages and disadvantages. It certainly supports a much smaller subset of conio functionality than TurboC, and requires you to modify your source code much more extensively.Borland supposedly has (or will soon have) a Linux version of their C++ compiler. At this point, the nature, price, and target platforms of this compiler are mysteries. One presumes that (like Kylix) it will be Wine-based, and therefore will work only on 'x86 systems. Nevertheless, if it contains the various library functions implemented in the TurboC library -- and frankly, that's a very big "if" -- it might provide a simpler means of porting your Turbo C programs to Linux. Speaking for myself, even though I have been a long-time Borland user, I philosophically prefer to compile my program with GNU gcc.
For graphics.h functionality, there is the GRX library of Csaba Biegl, Michael Goffioul, and Hartmut Schirmer. I didn't discover this library until I had only a few graphics.h functions left to write, and I haven't fully evaluated it. Its stated aim is to be a multi-platform 2D graphics library. Its website does not advertise (or even mention) Turbo C compatibility. However, it contains quite a few functions of the same name (and, apparently, the same functionality) as Turbo C library functions.
Of course, if you are only interested running your program on *nix systems -- as opposed to porting the program to *nix systems in general -- you might be able to simply run your existing executable using one of the freely available DOS emulators for Linux. DOS emulation using dosemu with freedos works very well on 'x86 systems, while bochs with freedos works well (if somewhat slowly) on non-'x86 *nix systems.
Sunday, September 14, 2008
My Learnings...
We perform an activity about it.

I learned the steps on how to make a program.
The first thing you have to type is the :
#include
it is very important in starting your program.
And the last thing that you have to type is:
getch();
}
In every program, the semicolons, brackets, parenthesis and eto. are very important because your program will not run if there is a semicolon or something you think that is not important that is missing.
turbo c (september 14)

Last week we just tackled on how to use the turbo combined programming language. We also have a activity using turbo c programming language.
How to start a program???