W e b t u t o r i a l s

Programing Approach

Algorithm, Flow Chart

Define C

Define Programming

C - Syntax

C - Variables

C - Keywords

C - Data Types

C - Comments

Turbo C - Shortcut keys

C - Operators

Hierarchy of Operators

Ex: Arithmetic Operator

Control Structure

Control Structure - if

Ex: If condition

Ex: Inc / Dec Operator

C - loops

Ex: Loops

C - Nesting Of loops

Ex: Nested Loops

Constant Variable

C - Escape Sequence

C - Arrays 1D, 2D

C - Sorting


Character I/O Function

C - Strings

Ex: Strings

Array of Strings

C - Math Functions

C - Functions

C - Types of Functions

Storage Class

C - Header Files

C - Preprocessor

C - Pointers

C - Structures

Typedef File Handling

Command Line Argument



Typedef statement is use to define a new data type that are equivalent to existing data type.

Syntax: Typedef int num

File Handling

Sometime it is necessary to store the output in a file instead of just displaying it. In C Language this can be done by using file handling.

File Modes:

Sno Modes Description
1. r Opens an existing text file for reading purpose.
2. w Creates a new text file for writing purpose. If file already exists, then it open the file and overwrite it.
3. a Open a text file for writing in append mode, if it does not exist then a new file is created.
4. r+ Opens a text file for reading and writing both.
5. w+ Opens a text file for reading and writing both. It first truncate the file to zero length.
6. a+ Opens a text file for reading and writing both. It creates the file if it does not exist. The reading will start from the beginning but writing can only be appended.
File Operations
1. Create a new File
2. Opening an existing File
3. Reading from a file
4. Writing to a file
5. Searching in a file
6. Closing a file

Functions used in File Handling

1. fopen() – opening a file
Syntax: filepointer=fopen(“filename.ext”,”mode”);

2. fclose() – closing a file
Syntax: fclose(filepointer);

3. fgetc() or getc – use to read a single character from a file at a time.
Syntax: char ch=fgetc (filepointer);

4. fputc() – write a character in a file.
Syntax: fputc(char variable, filepointer);

5. fputs() – write a string in a file.
Syntax: fputs(string, filepointer);

6. fgets () – read a string from a file.
Syntax: fgets(string, numberofcharacters, filepointer);

void main()
FILE *fp;
char ch;

7. fprintf() – Write a record in a file.
Syntax: fprintf (filepointer,”%s %d”, e.name, e.age);

8. fscanf() – reading a record from a file.
Syntax: fscanf( fp, “%s %d”, &e.name, &e.age);

9. fwrite() – write a record in a file
Syntax: fwrite(&object, sizeof(object), 1, fp);

10. fread() – read a record from a file
Syntax: fread(&object, sizeof(object), 1, fp);

11. fseek() – search a record
Syntax: fseek (fp, -recsize, SEEK_CUR);

12. remove() – to delete a file
Syntax: remove (“filename.txt”);

13. rename() – to rename the file
Syntax: rename (“Oldfilename”, “Newfilename”);

14. ftell() – to locate the current position
Syntax: ftell (filepointer);

15. feof() – to locate end of file
Syntax: !feof(fp) – runs the loop till end of file.

if (fp==NULL)

1. count number of vowels, characters, words
2. Copy contents of one file into another.

If you are going to handle binary files then you will use below mentioned access modes instead of the above mentioned:
"rb", "wb", "ab", "rb+", "r+b", "wb+", "w+b", "ab+", "a+b"