You are on page 1of 21

Language : It is a medium of communication, with set of instructions, which incl udes input, processing and output.

Types of Languages: 1. High Level Language : It communicates with simple English. It gives readabili ty. (PASCAL, FORTRAN, COBOL,.........etc.) 2. Low Level Language : It communicates with few special codes, which does not g ive readability. (MASM - Macro Assembler TASM - Turbo Assembler) 3. Middle Level Languages : it is a combination of low and high level languages. (C, C++, Java,.....................etc.) History of C Language : Year 1960 1963 1967 1970 1972 Name of Software ALGOL 60 Developed by / at International committee

CPL " " (Combined Programming Language) BCPL Martyn Richards (Basic CPL) (Cambridge University) B Ken Thompson (AT & T Bell Labs) C (Dennis Retchie) (AT & T Bell Labs)

AT & T stands for American Telecommunications and Telegraphs Translators: 1. Compilers - compiles the complete program at a time and detects all the error s at once and provides fast execution of program. (Pascal, Cobol, C, C++,.....................etc.) 2. Interpreters - it translates and executes the program in step by step process . Program execution is slow. (BASIC, FOXPRO) 3. Assemblers Types of Programs: A program in computers can be written in different ways; 1. Procedural Program - direct instructions are enclosed in a program. (BASIC) 2. Structured Program - before writing user instructions, few predefined instruc tions related to that language should be written. (Cobol, Pascal, C, ...................etc.) 3. Object Oriented Program (OOPs) 4. Event driven Program Note:

1. C is Middle Level Language, becoz it can interact with hardware components o f computer. 2. C is Compiler oriented language 3. C is Structured + Procedural Programming language 4. C is case sensitive. Structure of C Program: [ pre processor ] [ global declaration ] [ linkage section ] void main() { [<declaration part>]; execution part; } Flavours of C Language: (Compilers of C Language) 1. 2. 3. 4. RUNC (CUI) Borland C (GUI) ANSI C (Unix / Linux) Turbo C (Win)

Invoking Editor OF C Language: After copying the C language software into c drive. To open Editor of C Language, for easy interaction: C:\> Cd Turboc2 C:\Turboc2> tc Editor of C Language contains 2 blocks. 1. Documentation Area (which program is written) 2. Message Area (provides list of errors which are occured in a program) To Compile the program: ALT + C or ALT + F9 To Execute the Program: ALT + R To Compile and Execute the Program: CTRL + F9 To View The Output Of a Program: ALT + F5 To write a C program without editor: 1. write a c program in any editor (Notepad, edit, ...etc) 2. Compile the program c:\Turboc2> TCC filename.c 3. Execution of prgram C:\Turboc2>filename Writing a C Program in ANSI C (UNIX / LINUX): $ vi filename.c To save the program :x

$ cc filename.c OR

or

$ gcc filename.c

$ cc filename.c -o new_filename (stores the output of a c program into a require d file) To Execute the program $ ./a.out (default file created for all c programs. it stores the recent program s output) or $ ./new_filename (getting the output of c program thru a separate file) Pre processor: #include #define #ifdef #else #undef #include : this preprocess is used to enclose header files and it also supports to enclose user created c programs. In this # include, # is called Directive. Syntax : #include <filename.h> or #include "filename.h" or #include "FILENAME.H" Header file : it is a file provided by software it consists of predefined functions and predefined symbolic constants. it allows a user to use the features provided by header files. Header files are created based on the natures of functions. C language provides approximate of 23 header files. These files are used in a program thru a preprocessor called #include. C supports to work with various header files STDIO.H (Standard Input and Output Header File) CONIO.H (Console Input and Output) MATH.H (Mathematical Functions) DOS.H PROCESS.H STDLIB.H GRAPHICS.H ............................................etc. Output function of C Language: printf("[Message] [Format Specifiers] [Escape Seq's]", variables_list); This functions is provided by "stdio.h" header file. In this function 'f' stands for formatted or function. It performs 2 tasks 1. Displays messages 2. Displays memory values Escape Sequences:

These characters are used at output statement of C Language. It provides its affect only in the output. These characters are preceeded by \ These characters can be used for any number of times. C - Language supports to work with the following escape characters; \n - new line or next line \t - horizontal tab \a (alert) | \007 | Beep Sound \r - Carriage return \0 - Null Character \v - vertical tab \f - Form Feed \" - displays double quotes on screen Representation of Data: Data in C Language is represented based on the following key points; 1. Data Name 2. Data Type 3. Data Size 1. Data Name : It is often called variable. It is the one which stores data. It can store only 1 value. If more than 1 value is stored it gives priority to last value. It should be declared before it is used in a program. Rules to be followed before using Data Name: i. Variable can be min of 1 char and max of 32 chars (practically it is possible to create more than 32 chars for a variable name) ii. Variable cannot be enclosed with blank spaces and special characters except Underscore (_) iii. Variable cannot get start with numbers iv. Variable can get start with alphabets or underscore v. Variables should be always unique Data Types: It explains regarding type of data to be stored into a data name. Data types are classified into 2 categories Primary Data Type (Primitive Data Type) 1. Integers 2. float 3. char 4. double 5. void Secondary Data Type (Derived Data Type) 1. Arrays 2. Structures 3. Unions 4. Pointers 5. enum (enumerated)

1. Integers : This data type will support to store only numbers. It can store on ly integer values. These are classified into 4 types; 1. 2. 3. 4. int or signed int (default) - 2 bytes , -32768 to 32767 unsigned int - 2 bytes short int - 2 bytes ( 0 to 65534) long int - 4 bytes

2. Float : It is used to store real numbers (only integers or only value after d

ecimal point can be stored). It is represented by a keyword called "float" memory is allocated of 4 Bytes value can be -3.4E38 To 3.4E38 3. char: It is used to store any type data. Default memory is of 1 Byte Value can be stored from -128 to 127. If a variable is specified by size then it is called String variable or Character Array. When String variable is declared size can be specified from 1 t o 65535 characters. char name; name='A'; or name='+'; or name='8'; name='Shareef'; -- invalid (error) name='86' -- invalid (error) name=86; -- valid or char name[12]="Shareef Hyd"; -- string variable or character array, supports to store group of characters. scanf(): It is an input function. It is used to accept input from a user for variables related to differen t data types at the execution of a program. In this function 'f' stands for formatted or function. This function is provided by Stdio.h Syntax: scanf("[Escape Seq's] Format Specifiers",vars); When variables are used in scanf(), it should be preceeded by &, except string v ariable. when float variables are used in scanf(), format specifier should not be provide d with decimal points. Format Specifiers: They can be used in input and output functions. They are differentiated based on data types. %d - int %f - float %c - char %s - string %ld - long int %e - double %u - unsigned Assignment Operator : = Relational Operators: >,>=,<,<=,==,!= Logical Operators: And - && Or - ||

Not - ! IF CONDITIONAL STATEMENT: It is used to compare the data providing the result on boolean expressio n i.e. TRUE or FALSE. C-Language will support to work with the following conditional statement s; 1. Simple-If Conditional Statement 2. If-Else-If Conditional Statement 3. Nested If Conditional Statement 1. Simple-If : At this conditional statement it is used to compare the data and also supports to write 1 true and 1 false statement or block. If multiple statem ents are to be executed on condition then it should be enclosed in compound stat ements. Syntax: if (condition) true statement; [else false statement;] if (condition) { statements; } else { statements; } IF-ELSE-IF conditional statement: At this conditional statement, if condition is followed by the other if conditional statement. If no condition is satisfied it will interact with else s tatement. Syntax: if (condition1) { statements; } else if (condition2) { statements; } else if (condition3) { statements; } else { statements; }

NESTED IF CONDITIONAL STATEMENT: If condition is used within an if condition refers to nested if conditio nal statement. Syntax: if (condition1) { statements; if (condition2) { statements; } else { statements; } } else { statements; }

GOTO Statement: It is called branching statement, since it supports to transfer the cont rol from 1 part of a program to other part of a program. It works based on 2 concepts; 1. Label Assignment- goto label_name; 2. Label Definition - label_name: Binary Operators: +,-,*,/,% are called binary operators, since it uses 2 operands. Unary Operators: +,- are called unary operators, since it works on 1 operand It includes Post & Prefix operators or often called post and pre increment , dec rement operators. var ++ ++ var var ---var Post Increment Pre Increment Post Decrement Pre Decrement

Points to be remembered to work with post and prefix operators: 1. When post and prefix operators are used as invidual expression, there is no d ifference encountered between post and pre. 2. By default it increments and decrements max of 1 value.

3. When post and prefix operators are used in print(), it performs its task in t he following way; i. When post increment is used, first prints then increments. ii. When pre increment is used, first increments then prints. iii. when post decrement is used, first prints then decrements iv. When pre decrement is used, first decrements then prints. 4. When post and prefix operators are enclosed in a single printf(), it always s tarts from right to left. 5. When Post and Prefix operators are assigned to other variable, it performs it s task in the following way; i. When Post increment is assigned, first assigns then increments ii. When Pre increment is assigned, first increments then assigns iii. When Post decrement is assigned, first assigns then decrements iv. When pre decrement is assigned, first decrements then assigns Short Hand Operators: These operators will allow a user to modify the variable with more than 1 value. It can be used with all arithmetic operators. var+= var-= var*= var/= var%= LOOPING CONSTRUCTS: LOOP: Execution of 1 or more statements repeatedly until a given condition is sa tisfied refers to Loop. C-Language supports to work with the following looping constructs; 1. do...while 2. while.... 3. for.... 1. do...while looping construct: This looping construct will support to execute the instructions repeated ly till the condition is satisfied. Syntax: do { statements; }while (condition); 2. while looping construct: This looping construct will also support to execute 1 or more statements repeatedly until a condition is satisfied. Syntax: while (condition) [;] { statements;

} Differences between do...while and while... looping constructs: ============================================================================= DO..WHILE WHILE ============================================================================= 1. Min of once statements gets 1. Statements gets executed executed only when condition is satisfied. 2. First executes statements 2. checks the condition and then checks the condition and then executes the s tatements 3. Must that while loop should be 3. It is optional terminated by ; ============================================================================= For Looping Construct: This looping construct will support to execute 1 or more statements repe atedly until a given condition is satisfied. syntax: for ([initial val];[condition];[modifier]) [;] { statements; } Differences between For Looping and while looping construct: ============================================================================= For Loop While Loop ============================================================================= 1. Initial value, condition and incr 1. initial value, condition can be in same line. and increment all should be at different lines. 2. It is unconditional looping 2. It is a pure conditional construct. looping construct. ============================================================================= Swich Case Statement: It supports to group the statements in the form of blocks and will execu te them based on users choice. If given choice is not found then it executes Default block. Choice can be given of numbers or alphabets or spl characters. Choice can be given only of integers. Break in Case Block is used to terminate that block. Default block can be written anywhere in Switch case statement. Last block of switch case statement should not be terminated by break Multiple values can be provided for a single case block. Case block values should always be unique. Syntax: switch (var) { case n/'c':

statements; break; case n/'c': statements; break; case n/'c': statements; break; default: statements; } Note: Switch case statement is similar to If conditional statement, where amon g these 2 if conditional statement is assumed to be the best concept, since the task of multiple lines can be completed in a single line. switch (ch) { case case case case case } Strings Functions: String is defined as group of characters. String variable can be created by specifying the size, which can be from min of and max of 65535 locations. String Variable is often Called As "Character Array". Every string should be terminated by null character and it is represente d by \0. When string variable is declared, size cant be specified as 0 or -ve val ue or cant be left for blank. Memory to a string always gets allocated from 0 to size-1. char str[ ] ; error char str[0]; error char str[1]; char str[65535]; char str[12]; When a string is accepted using scanf(), it terminates the string with n ull character whenever blank space occurs. gets(str_var): This input function is used to accept a string with blank spaces and gets terminated with null character only when enter key is pressed. puts("Message"/str_var) : It is an output function, which will support to write either message or variable. Note: These functions are provided by a header file called "Stdio.h". String Functions: These Functions are used to perform operations on string type data. if (ch>=1 && ch<=5) statements; 1: 2: 3: 4: 5: statements;

C language supports to work with following predefined functions. 1. strlen(string) - finds the length of a given string 2. strcpy(tar_str,src_str) - copies the string from 1 var to other var 3. strcmp(str1,str2) - to compare 2 strings and returns 0 if strings are equal e lse returns difference of ASCII codes. 4. strlwr(string) - converts from upper case to lower case 5. strupr(string) - converts from lower case to upper case 6. strncpy(tar_str,src_str,number) - it is to copy n no. of characters from src to target 7. strncmp(str1,str2,n) - it compares n number of characters from 2 strings. 8. strstr(str1,str2) - it is used to search for sub string in a main string. 9. strrev(str) - it is used to reverse a given string. Note: All the string functions are provided by String.h header file. Arrays It is a technique of storing more than 1 value in a single variable with similar type data refers to Array. OR Homogeneous type data stored into a single variable refers to Array. Arrays are classified into 3 types; 1. Single or One Dimensional Array 2. Double or Two Dimensional Array 3. Multi Dimensional Array 1. Sinle or One Dimensional Array: It is a process of storing more than 1 value in a single variable with s imilar type data arranging data only in ROW format. Syntax: Data_Type var1(size),var2(size),var3(size),..................... ............; Note: 1. Size can be specified with min of 1 and max of 32767 2. Size is must 3. When array var is declared, size cant be with 0, -ve value and cant b e left for blank. 4. Index Variable plays an important role, to interact with different lo cations of array. 5. Array variable gets allocated by memory from 0 to size-1. 6. When Single Dimensional array is declared and initialized, size is op tional. 7. When Single Dimensional array is declared and initialized, if less el ements are stored than the size specified, the other locations provide the defau lt value as 0. sizeof : This operator is used to know the memory allocated for a variable or pr ovided for a data type. 2. Double or Two Dimensional Array:

At this array concept it will support to store more than 1 value in a si ngle variable arranging the data in the form of rows and columns. Syntax: Data_type var1[size][size],var2[size][size],............................ .......; To Interact with the locations of double dimensional variable 2 index va riables are required. When Double Dimensional array is declared and initialized, size to rows is optional and columns is must. 3. Multi Dimensional Array : It supports to use double dimensional array for n times. Syntax: Data_type var1[size][size][size],....................................... ...................; Example: int a[3][2][2];

It represents for 2*2 matrix being used for 3 times.

STRUCTURES It is a technique of storing more than 1 value in a single variable with dissimilar type data. OR Heterogenous type data stored in a single variable refers to structure. Structures are classified into 3 types; 1. Simple Structure 2. Nested Structure 3. Self Referential Structure 1. Simple Structure : It is a process of storing more than 1 value in a single variable relate d to different data types. Syntax: struct [<tag_name>] { member 1; member 2; ......... member n; }[<var1,var2,..........>]; Note: 1. 2. 3. 4. ue 5. Tag name to a structure is optional A keyword called "struct" is used Structure can be created as local or global More than 1 structure can be created in a single program but always with uniq tag names. Structure members created in 1 structure the same can be created in the other

structures, since structures are different it treats members as different. 6. Structure variables created for 1 structure the same cant be provided for the other structures. 7. Structure variable can be declared directly associating to a structure or it can be declared in a separate line. struct tag_name var1[,var2,var3,.................]; 8. Access Operator or dot operator plays an important role, since it differentia tes between structure var and member. 9. Structure members cant be assigned with values directly into a structure. 10. Structures will not allow to write functions. Nested Structure: A structure which is created within the other structure refers to nested structure. To access the members of nested structure, 2 access operators shoul d be used. Syntax: struct tag_name1 // Outer Structure { member 1; member 2; ......... struct tag_name2 // Inner Structure { member 1; member 2; .......... }[<var1,var2,var3,......>]; }[<var1,var2,var3,..............>]; Structure variable as Array: A variable created for a structure can be of Array Type, which supports to store multiple records into one variable. Index variable should be associated to structure variable. Syntax: struct [<tag_name>] { member 1; member 2; ............ member n; }[<var1[size],var2[size],.................>]; Structure Member As Array: A member of structure can be of Array type, which supports to store set of values in a single member. Index variable should be associated to structure m ember. Syntax: struct [<tag_name>] {

member 1[size]; member 2[size]; ............... }[<var1,var2,.................>]; Assigning constant values for a structure variable: Constant values can be assigned to a structure variable always in a sequ ence the way members are placed in a structure. If any data is skipped then it w ill store default value as Zero. Constant Values can be specified into Structure variable which stores 1 record or can store multiple records. UNIONS Unions are similar to structures, being differed at 1 point, where struc tures will be allocated by memory for all its members whereas Unions will alloca te memory to only that member which has biggest size. Syntax: union [<tag_name>] { member 1; member 2; ............ member n; }[<var1,var2,var3,..................>]; Differences between Structures and Unions: ============================================================================= Structures Unions ============================================================================= 1. It will allocate memory to all the members. 1. It will allocate memory to on ly that member which has bi ggest size. 2. It will store and access all values. ast value by ers. 3. When constant values are assigned, it will ned and support to specify values for all members. y all the 2. It will access only l all the other union memb 3. Only 1 value is assig that value is accessed b

other union members. ============================================================================= USER DEFINED FUNCTIONS Function is defined as , "Self Contained Program, which returns maximum of 1 val ue". Returned value can be any type data. It is a process of splitting a large application program into small modules or b locks. Advantages of User Defined Functions:

1. Readability of a program gets enhanced 2. Writing of code gets decreases 3. Error Detection and Modification is Quite Easy Components of User Defined Functions: 1. Function Prototype or Declaration 2. Function Call 3. Function Definition or Body of a Function Points to be remembered to work with user defined functions: 1. Function can be called for any number of times. 2. A Function which is calling other functions refers to Calling Function 3. A Function which is being called thru Calling Function is called "Called Func tion". 4. A called function in turn can call other functions. 5. Definition of called function can be on top or bottom of calling function. 6. Function prototype can be local or can be global. 7. Function call with function definition leads to runtime error. 8. Function definition with no function call is valid. 9. Function Definition may exist in a program file where it is called or it may exist in the other program file, where a link is created using #include preproce ssor. #include "FileName.c" 10. Function definition and prototype should always be unique. 11. Function name should not get start with numbers. 12. Function name should not be enclosed with blank spaces and special character s, Except underscore 13. Sending and receiving parameters should be same in number and should be same in type. 14. Sending parameters is called Original Or Actual Parameters 15. Receiving parameters is called Formal Parameters. 16. Other name for Parameters is called "Arguments". 17. Function can be called within itself, it refers to "Recursion". Categories of Functions: 1. 2. 3. 4. Function Call With Arguments Function Call With No Arguments Functions with return value Functions with no return value

return : This keyword will perform 2 tasks; 1. Returns 1 value from called function to calling function 2. Terminates the function. void : It is a null data type. Function specified with return type as void will not allow a function to return value but it supports to write only return keyword, which will perform a task of terminating a function. Function Prototype (Function Declaration): It performs the following tasks; 1. Function Name 2. List of arguments with respect to number and types

3. About return type 3. Body of a Function. Recursion: A function being called within itself refers to Recursion. A recursive function can be created in 2 ways; 1. Direct Recursion 2. Indirect Recursion A recursive function can be made to restrict when it is called within it self, by specifying user defined conditions. Array as Argument: Single Dimensional Array (Integer or Character): When Array is transfered as Argument, It will send the reference of orig inal argument. Any changes are made to the Formal Argument, it will reflect into original argument. Array size to formal parameter and at prototype should not be specified. Double Dimensional Array: When Double Dimensional array is transfered as argument, at prototype of a function, size to the columns is must and for rows it is optional. The same c oncept is applied when function definition is created. Structure Variable As Argument: A variable created for structure can be transfered as argument, where it is essential that structure should be created as Global. Variable of that structure can be created as local or global. As Sending argument of struct type, it is essential that receiving argum ent will also be of struct type. Any Modifications are made to the formal argume nt will not reflect on the original argument. When prototype of a function is cr eated, argument should be specified with structure name. STORAGE CLASSES: It explains regarding nature and behaviour of variable at the execution of a program. These classes will perform the following 4 tasks; 1. 2. 3. 4. Explains Explains Explains Explains Where the Variable is stored? default initial value assigned to a variable? about Scope of a variable? about Life of a variable?

C-Language will support to work with the following storage classes; 1. 2. 3. 4. Automatic Storage Class Register Storage Class Static Storage Class Extern Storage Class

1. Automatic Storage Class This storage class is represented by a keyword called "auto". It performs the following tasks;

1. 2. 3. 4.

Storage Default Initial Value Scope of a variable Life of a variable -

Memory Garbage Value local to the block in which it is defined Till the control is in the block.

2. Register Storage Class This storage class is reprsented by a keyword called "register". It performs the following tasks; 1. 2. 3. 4. Storage Default Initial Value Scope of a variable Life of a variable Register Garbage Value local to the block in which it is defined Till the control is in the block.

3. Static Storage Class This storage class is reprsented by a keyword called "static". Memory to static variable will be allocated only for once. It performs the following tasks; 1. 2. 3. 4. Storage Default Initial Value Scope of a variable Life of a variable Memory 0 local to the block in which it is defined Value gets persist at different function calls.

4. Extern Storage Class This storage class is reprsented by a keyword called "extern". It performs the following tasks; 1. 2. 3. 4. Storage Default Initial Value Scope of a variable Life of a variable Memory 0 Global Till the program does not come to an end

Global Variable: A variable which is declared on top of main function, refers to Global V ariable. It can be accessed in a complete program. Any Modifications are made to a global variable, it reflects in the rest of the program. Variable declared in Global and if the same variable is declared in loca l, priority is given to local variable and in rest of the program it gives prior ity to global variable. Note: When extern variable is created, it is compulsory that the same variable should be declared either on top or bottom of main(). Extern variables should not be initialized. Extern variable is declared in a block but will work in a complete progr am. POINTERS It is a variable which will support to access the data in indirect way. C-Language will support to access the data in 2 ways; 1. Direct Accessing 2. In-direct Accessing

1. Direct Accessing: It is a process of accessing the data using a variable where data is sto red. 2. In-direct Accessing: Data stored in 1 variable can be accessed with the help of other variabl e. Advantages: 1. Speed of execution of program gets enhanced 2. More than 1 value can be returned from called function to calling function. 3. Memory can be saved. Properties of a variable: Variable declared with any data type is provided with following 3 prope rties. 1. Location Name 2. Value at Location 3. Address of Location Points to be remembered to work with Pointers: 1. A variable can be provided with min of 1 pointer and max of 255 pointers. 2. Two Special Characters plays an important role. 2.1. & - Address or Reference Operator 2.2. * - Indirection Operator or Value at Address Operator 3. A variable without pointer is reserved to store data whereas a variable with pointer is used to store Address or Reference. 4. In C-Language, Address is always of Signed Int. 5. To display the address from signed int to unsigned int, %u conversion charact er is used. 6. Every pointer variable will be allocated with a memory of 2 bytes, since addr esses are made of int type. Array of Pointers: A variable declared with * of character data type, by default will work string. It will store the memory at the locations where continuous memory is fou nd and its base address will be stored in a pointer variable. By using that poin ter variable string gets accessed. Pointer To Array: Array variable of any type is accessed by using its base address. The fi rst member of an array is used as base address. Using the base address the compl ete string can be accessed. Pointer to Structure: When a structure variable data gets accessed in indirect way, first mem ber of a structure its address will act as base address. When structure data gets accessed in indirect way, arrow operator (->) i s used. Call by Value & Call By Reference:

Call By Value: At this concept data of original arguments will be copied to Formal Argu ments. As original arguments are of value type, it is essential that receiving a rguments should also be of value type. Any modifications are made to formal argu ments will not reflect on original argument. Call By Reference: At this concept address or references of original arguments will be copi ed to formal arguments. As addresses of original arguments are being sent to for mal arguments, hence formal arguments should be of pointer type. Any modificatio ns are made thru formal arguments will reflect on original arguments. Internally called function can return multiple values in calling function. Dynamic Memory Allocation (DMA): It is one of the main features of C Language, which supports to create d ynamic memory of 'n' locations at runtime. It overcomes the drawback of arrays, where memory of array will be static, which neither gets increases nor gets decr eases. Dynamic memory allocation is implemented with the help of following func tions: 1. malloc() : it will allocate dynamic memory of 'n' locations and default valu e which stores in that memory will be garbage value. It works with 1 argument. Syntax: pointer_var=(data_type *)malloc(no_of_locations*sizeof(datatype)); 2. calloc() : it will allocate dynamic memory of 'n' locations and default valu e which stores in that memory will be 0. It works with 2 arguments. Syntax: pointer_var=(data_type *) calloc(no_of_locations,data_type); Dynamic memory can be deallocated using the following function: 3. free(ptr_var) : It is used to deallocate the memory. Note: When These functions are used in a program, alloc.h header file should be enclosed. Functions returning reference: A called function can be made to return reference. When a function retur ns reference it is essential that nature of a function from returning value to r eturning of reference should be specified at prototype and func definition. syntax: return_type *func_name(list_of_args); FILES Collection of es; 1. Program Files - It cessing and output. 2. Text Files - which tted file. 3. Data Files - which characters refers to File. A File is classified into 3 typ contains set of instructions with a format like input, pro contains collection of characters and it is called unforma contains data for future reference.

Files concept w.r.to text and data files in C language gets implemented with the help of following functions; 1. 2. 3. 4. 5. 6. fopen() fclose() fcloseall() remove() rename() rewind()

fopen() : It is used to open a file with different file opening modes. When a file gets opened it will interact with a file using file pointer, which i s created with a symbolic constant i.e. FILE. This constant will create a relati onship between os and language. syntax: file_ptr=fopen(file_name,file_opening_mode); file_name is a string type data file opening modes: It explains regarding purpose of opening a file. A file can be opened to perform various tasks like reading, writing, app ending,..........................etc. w r a w+ r+ a+ wb+ rb+ ab+ file gets opened in "write" mode file gets opened in "read" mode file gets opened in "append" mode file gets opened with write + read mode file gets opened with read + append mode file gets opened with append + read mode write operation in binary mode read operation in binary mode Append operation in binary mode

2. fclose(file_ptr) : It is used to close a file. 3. fcloseall() : It is used to close all the files 4. remove(file_name): It is used to delete a file. 5. rename(src_file,target_file) : It is used to rename a file 6. rewind(file_ptr) : It is used to transfer the file pointer from end of file t o beginning of a file. Text Files : File is collection of characters. To work with text files, following functions are used. 1. putc(char,file_ptr) - it is used to store the character accepted from a user into a file. 2. fputc(char,file_ptr) - it is similar to putc() 3. char_var=getc(file_ptr) - it is used to read the character from a file. 4. char_var=fgetc(file_ptr) - it is similar to getc(). Data Files: It is used to store the data , which is accepted from a user at the exec

ution of a program for future reference. It will also support to perform operati ons on that store data. Sequential Data Files: C-Language is used to store and read the data with the help of following functions. 1. fprintf(file_ptr,"Format Specifiers",list_of_variables); In this function f stands for file and formatted. It will support to store the data into a file. 2. fscanf(file_ptr,"Format Specifiers",list_of_variables); It is used to read the data from a file into buffer variables. Random Data Files: These files will support to store and read the data from a file using St ructures. 1. fwrite(): It is used to store the data accepted from a user at the execution of a program using structures into a file. When this function is used file should be opened in Write Mode. Syntax: fwrite(ptr_var,size_of_struct_var,no_of_recs,file_ptr); 2. fread(): It is used to read the data from a file which is stored with a suppo rt of structure. When this functions is used file should be opened with Read Mode. Syntax: fread(ptr_var,size_of_struct_var,no_of_recs,file_ptr);

You might also like