"Life is not a problem to be solve but a reality to be experience"
TURBO C PROGRAMMING The History of Turbo C Language is an Integrated Development Environment and compiler for the C programming language from Borland. Firstintroduced in 1987, it was noted for its integrated development environment, small size, extremely fast compile speed,comprehensive manuals and low price.In May 1990, Borland replaced Turbo C with Turbo C++. In 2006, Borland reintroduced the moniker.The beginningsIn the early 1980s, Borland enjoyed considerable success with their Turbo Pascal product and it became a popular choice
when developing applications for the PC. Borland followed up that success by releasing Turbo Basic, Turbo Prolog andTurbo C.Turbo C had the same properties as Turbo Pascal: an integrated development environment (IDE), a fast compiler, a goodeditor and all that for a cheap price. Nevertheless, Turbo C was not as successful as the Pascal-sister product. First, Cwas not a school language such as Pascal, but rather a language for professional programming and systemsdevelopment. Turbo C was therefore competing with a full field of professional programming tools (Microsoft C, LatticeC, Watcom C, etc.). Turbo C did, however, have advantages in speed of compiled code, the ability for large projects to beimplemented, and compared to competing compilers a very low price.
Version history Version 1.0
, on May 13, 1987 - It offered the firstintegrated edit-compile-run development environmentfor C on IBM PCs. The software was, like manyBorland products of the time, bought from another company and branded with the "Turbo" name, in this case
Wizard C
by Bob Jervis (The flagship Borlandproduct at that time, Turbo Pascal, which at this timedid not have pull-down menus, would be given a faceliftwith version 4 released late in 1987 to make it look more likeTurbo C.) It ran in 384 kB of memory. It allowed inlineassembly with full access to C symbolic names andstructures, supported all memory models, and offeredoptimizations for speed, size, constant folding, and jumpelimination.
Version 1.5
, in January 1988 - This was anincremental improvement over version 1.0. It included moresample programs, improved manuals and other bug fixes. Itwas shipped on five 360 KB diskettes of uncompressed files, and came with sample C programs, including a strippeddown spreadsheet called mcalc. This version introduced the <conio.h> header file (which provided fast, PC-specificconsole I/O routines). (Note: The copyright date in thestartup screen is 1987, but the files in the systemdistribution were created in January 1988.)
Version 2.0
, in 1989 - The American release was in late1988, and featured the first "blue screen" version, whichwould be typical of all future Borland releases for MS-DOS. The American release did not have Turbo Assembler or a separate debugger. (These were beingsold separately as the product Turbo Assembler.)See this ad for details: Turbo C, Asm, and Debugger were sold together as a professional suite of tools.
http://www.scribd.com/doc/62396755/The-History-of-Turbo-C Some examples of the uses of C are: -Operating System -Language Compliers -Assemblers -Text Editors -Print Spoolers -Network Devices -Modem programs -Databases -Language Interpreters -Utilities Features of C Language -A simple core language, such as math functions or file handling provided by a standard set of library routines. -Focus on procedural programming paradigm which facilitates for programming in a structured style. -Parameters are always passed by value, never by reference. -C is flexible when it allows unrestricted conversion of data from one type to another, such as conversion of a character to its numeric equivalent. CHAPTER 1: FLOWCHARTING AND ALGORITHMS 1.1 Flowchart Defined
-"Use of symbols and phrases to designate the logic of how a problem is solved" (SCHN95).
-"A common method for defining the logical steps of flow within a program by using a series of symbols to identify the basic Input, Process and Output (IPO's) function within a program" (TRA196).
-"A two-dimensional representation of an algorithm; the predefined graphic symbols of a flowchart are used to indicate the various operations and the flow of control" (SWAZ89).
-"A diagram representing the logical sequence in which a combination of steps or operations is to be performed. It is a blueprint of the program" (LAPU86).
1.2 Algorithm Defined
-"Algorithm is a finite set of instructions that can specify a sequence of operations to be carried out in order to solve a specific problem of class of problems" (SWAZ89). Terminal Symbol Used to signify the beginning and end of flowchart Preparation or Initialization Symbol Signifies the preparation of data
Used to select initial conditions Used to represent instructions or group of instructions that will alter or modify a program's course of execution. Input / Output "Shows input and output. Data are to be read into the computer memory from an input device or data are to be passed from the memory to an output device" (SWAZ89) Processing
Performs any calculations that are to be done Decision Signifies any decision that are to be done
"Two alternative execution paths are possible. The path to be followed is selected during the execution by testing whether or not the condition specified within the outline is fulfilled" (SWAZ89) On-page Connector "Shows the entry or exit point of the flowchart" (SWAZ89)
"A non-processing symbol used to connect one part of a flowchart to another without drawing flowlines" (LAU86).
"Conserves space by keeping related blocks near one another, reduces the number of flowlines in complex programs, and eliminates cros lines from taking place" (LAPU86). Off-page Connector "Designates entry to or exit from one page when a flowchart requires more than one page" (LAPU86) Flowlines Signifies the process that is to be executed next Turbo C Environment Four Parts of Turbo C Environment 1. Main menu 2. Editor status line and edit window 3. Compiler message window 4. "Hot key" quick reference line Turbo C`s Main Menu
The main menu is used to choose an instructions for the Turbo C what to do. There are two ways of selecting the main menu, First, by arrow key to move and highlight the selected menu and followed by pressing the enter button. Second, by simply hitting the alt key + the desired menu to select.
Example: alt + F for file or alt + P for project.
Menu item with its description:
File - Loads and save files,invokes DOS, and handles directories. Edit - Invokes the Turbo C Editor. Run - Compiles, links and runs the program currently loaded in the work area. Compile - Compiles the program currently in the work area. Project - Manges multi-file projects. Options - Sets various compiler, linker, and the environment options. Debug - Sets various debug options. Break/watch - Manages debugger watch expressions and break points
Note: if some of the info above are wrong kindly take time to comment for revising the entry.
Submenus under File menu (SCH192)
a. Load-enables the user to select a file to be opened or loaded into the editor. b. Pick-enables the user to select a file based on the nine files previously opened or edited. c. New-lets the user edit a new file or start new programs. d. Save-store or "saves the file currently in the editor" (SCH192). e. Write to-enables the user to "save a file using a different filename" (SCH192). g. Change dir-enables the user to specify the defined path to change the default path or directory. h. OS Shell-"loads the DOS command processor" and lets the user "execute DOS command processor" and lets the user "execute DOS commands" (SCH192). i. Quit-lets the user to exit or quit Turbo C. Turbo C Language Hot Keys
Hot Keys F1 - Online help F2 - Saves the current file being edited F3 - Loads a file F5 - Zooms the window F6 - Switches between the window F7 - Trace F8 - Step F9 - Compiles and links your program F10 - Toggles between the main menu and the editor Alt-F1 – last help screen Alt-F3 – allows you to pick a file to load Alt-F5 – switches between environment screen and output screen Alt-F7 – previous error Alt-F8 – next error Alt-F9 – compiles file to .OBJ Alt-C – Compile menu Alt-D – Debug menu Alt-E – Edit menu Alt-F – File Menu Alt-O – Option Menu Alt-P – Program Menu Alt-R – Run Menu Alt-X – Quits Turbo C Ctrl-F1 – requests help about the item which contains in the cursor Ctrl-F9 – Runs the program
Data Types for Turbo C
Data Types There are five elementary data types in C: characters (char), integer (int), floating point, double floating point and void. "Values of type char are used to hold ASCII characters or any 8-bit quantity. Variables of type int are used to hold integer quantities. Values of type float and double are used to hold real numbers. Real numbers have both an integer and fractional component. The type void has three uses: The first is to declare explicitly a function as having no parameters. The third is to create generic pointers" (SCHI92).
TypeBidwidthRange char 8 0 to 255 int 16 -32768 to 32767 float 32 3.4E-38 to 3.4E+38 double 64 1.7E-308 to 1.7E+308 void 0 valueless Size and Range of Turbo C's Basic Data Types
Type Modifiers Except type void, the basic data types may have various modifiers preceding them. "A modifier is used to alter the meaning of the base type to fit the needs of various situations more precisely. The list of modifiers includes the following" (SCHI92:
signed unsigned long short
Type Bidwidth Range char 8 -128 to 127 unsigned char 8 0 to 255 signed char 8 -128 to 127 int 16 -32768 to 32767 unsigned int 16 0 to 65535 signed int 16 -32768 to 32767 short int 16 -32768 to 32767 unsigned short int 16 0 to 65535 signed short int 16 -32768 to 32767 long int 32 -2147483648 to 2147483647 unsigned long int 32 0 to 4294967295 signed long int 32 -2147483648 to 2147483647 float 32 3.4E-38 to 3.4E+38 double 64 1.7E-308 to 1.7E+308 long double 64 1/7E-308 to 1.7E+308
Keywords Keywords in C are reserved words that have a special meaning. Reserved words "reserved" by the programming language for expressing various statements and constructs. thus, these may not be redefined by the programmer (LIM99).
auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
VARIABLES, CONSTANTS, OPERATORS, AND EXPRESSIONS Identifiers Defined Identifiers are composed of a sequence of letters, digits, and the special character_(underscore). Avoid using names that are too short or too long. Limit the identifiers from 8 15 characters only (LIM99).
Variables Defined Variables are identifiers that can store a changeable value. These can be different data types (LIM99).
Rules for defining or naming identifiers/variables 1. It must consist only of letters, digits, and underscore. Example: _duh, num_1(correct) 2. It should not begin with a digit. Example: 1name, 3to3 (incorrect) 3. An identifier defined in the C standard library should not be redefined. Example: printf, scanf (incorrect) 4. It is case sensitive; meaning uppercase is not equal to the lowercase. Example: ans ≠ Ans ≠ aNs or anS or ANs or ANS 5. Do not include embedded blanks. Example: large num (incorrect) 6. Do not use of the C-language keywords as your variable / idetifier. 7. Do not call your variable / identifier by the same name as other functions.
Variable Declaration All variables must be declared before they may be used. The general form of declaration is shown here:
Type variable list;
Example: int i, j, k; short i, j, k;
Note: Before declaring variable, specify first the data type of the variable/s Variable must be separated by comma All declarations must be terminated by a semicolon (;)
Local Variables "Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variable are declared" (SARR97).
Example: #include <stdio.h> main() { int a,b,c; (these are local variables) _________; _________; _________;
Global Variables "Global Variable are know throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function" (SARR97).
Example: #include <stdio.h> int a,b,c, (these are global variables
Constants Defined Constants are identifiers / variables that can store a value that cannot be changed during program execution(LIM99). Example: const int count =100; Where integer count has a fixed value of 100
Arithmetic, Logical, Relational, and Bitwise Operators "Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are three classes of operators in C: arithmetic, logical and relational, and bitwise" (SARR97).
Arithmetic Operators
Operator Action + Addition - Subtraction * Multiplication / Division % Modulus Divisor -- Decrement a value ++ Increment a value
Relational and logical Operators "In the term relational operator, the word relational refers to the relationship values can have with one another. In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic. The key to the concept of relational and logical operators is the idea of true or false" (SCHI92).
Relational Operators
Operator Action > Greater than >= Greater than or equal to < Less than <= Less than or equal to == Equal != Not equal
ll OR true II true = true true II false = true false II true = true false II false = false
! NOT ! true = false ! false = true
Bitwise Operator
"Bitwise operations are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C's standard char and int data types and variants. Bitwise operators cannot be used on type float, double, long double, void or other more complex types" (SCHI92).
Operator Action & AND I OR ^ Exclusive OR (XOR) ~ One's complement >> Shift right << Shift left
The ? Operator
"? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form" (SCHI92).
Example: y=x>9?100:200 is equivalent to
if (x>9) y=100; else y=200;
Evaluation of Expression Expression refers to anything that evaluates to a numeric value (LIM99).
Examples: A. Evaluate the following: 1. Given: z=5; a=3; b=9; w=2; y=-5 Converting Mathematical Formula to C Expression
"To solve mathematical problems using the computer, the formula should be translated to the programming language to be used. Arithmetic comutation should be written as C expressions" (LIM99).
Example: x and y are greater than z can be converted to z=x>z&&y>z x is equal to 1.0 or 3.0 can be converted to x == 1.0 II x== 3.0 Structure of a Simple C Program <#include directive> <#define directive> main() { <variable declaration section> statements ... }
A. #include directive "contains information needed by the program to ensure the correct operation of Turbo C's standard library functions" (LIM02) Example: #include<stdio.h? B. #define directive "used to shorten the keywords in the program" (LIM02). Example: #define g gotoxy C. Variable declaration section - "it is the place where you declare your variables" (LIM02). D. Body of the program - "start by typing main() and the { and } (open and close braces). All statements should be written inside the { and } braces" (LIM02).
Note: Turbo C is a case sensitive program, therefore use lowercase letters only.
Commonly used include files in C language (SARR97).
1. alloc.h - declares memory management functions 2. conio.h - declares various functions used in calling IBM-PC ROM BIOS 3. ctype.h - contains information used by the classification and character conversion macros. 4. math.h - declares prototype for the math functions. 5. stdio.h - defines types and macros needed for standard I/O. 6. string.h - declares several string manipulation and memory manipulation routines.
Important Symbols (SARR97).
\n - is a line char used to move the cursor to the next line ' ' - single quote is used for single character / letter " " - double quote is used for two or more character { - open curly brace signifies begin } - close curly brace signifies end & - address of operator * - indirection operator / pointer Input and Output Statements
Input Statement - a statement used to input a single character or a sequence of characters from the keyboard (SARR97). 1. getch - "a function used to input a single character from the keyboard without echoing the character on the monitor" (SARR97). Syntax: getch(); Example: ch=getch();
2. getche - "a function used to input a single character from the keyboard, the character pressed echoed on the monitor, like the READLN in PASCAL" (SARR97). Syntax: getche(); Example: ch=getche();
3. getchar - "a function used to input a single character from the keyboard, the character pressed echoed on the monitor, terminated by pressing ENTER key" (SARR97). Syntax: getchar(); Example: ch=getchar();
4. gets - "a function used to input sequence of character from the keyboard, spaces are accepted, terminated by pressing enter key" (SARR97). Syntax: gets(); Example: gets(ch);
5. scanf -"a function used to input single character or sequence of characters from the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Syntax: scanf("control string codes", identifier); Example: scanf("%d", &num);
Output Statement - a statement used to display the argument list or string on the monitor (SARR97).
1. printf - "a function used to display the argument list on the monitor. It sometimes needs the control string codes to help display the remaining argument on the screen" (SARR97).
2. putchar - "a function used to display the argument list or string on the monitor. It is like overwriting a character" (SARR97). Syntax: putchar(); Example: putchar(tolower(ch));
3. puts - "a function used to display the argument list or string on the monitor. It does not need the help of the control string codes" (SARR97). Syntax: puts(); Example: puts("hello");
Format Strings and Escape Sequences All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data re to be formatted (SARRI97).
List of commonly used format specifiers:
%c - used for single char in C scanf("%c", &ch); printf("%c", ch); %d - decimal number (whole number) scanf("%d", &num); printf("%d", num); %e -scientific notation / exponential form scanf("%e", &results); printf("%e", result); %f - number with floating or decimal point scanf("f", &pesos); printf(%f", pesos); %o - octal number scanf("%o", &value); printf("%o", value); %s -string of characters scanf("%s", &str); printf("%s", str); %u - unsigned number scanf("%u", &nos); printf("%u", nos); %x -hexadecimal number scanf("%x", &value); printf("%x", value); %X - capital number for hexadecimal number scanf("%X", &nos); printf("%X", nos); %% - print a percent sign scanf("%%", &value); print("%%", value);
List of commonly used escape sequences
\\ - prints backslash \' - print single quotes \" - print double quotes \? - prints question mark \n newline
Note: A function gotoxy is used to send the cursor to the specified location. Syntax: gotoxy(x,y); Example: totoxy(5,10);
Examples:
1. Make a program that will display the word "Hello", "I'm fine", and "Thank You" in different lines and column.