II Bcom Structuring-Programming-Through-C
II Bcom Structuring-Programming-Through-C
Programming is the process of solving a problem with computer. The five steps in the
programming process are listed below
1) Statement of problem 2) Development of solution 3) Coding 4) testing and debugging
5) Documentation
1) Statement of problem: Definition of a problem can be best achieved by writing
down the problem in clear statement. Better problem definition results in faster and accurate
solutions.
2) Solution development: this is the creative part of the programming process. At
this stage we have to construct a step by step procedure of solution. The useful tools in
development of a solution are (1) Algorithm (2) Flow Chart.
An algorithm is descriptive step by step problem solving procedure that can
be carried out by a computer.
A Flow chart provides visual representation of solution.
3) Coding: the next step in programming process is coding. This is the process of
converting a solution into o an actual computer program. Here the programmer has to choose
a particular programming language.
4) Testing & Debugging: Once coding is complete, we will enter the program into
the computer test it. We must verify that our program does everything that is supposed to do
the testing of program involves debugging. Debugging the process of finding out and
removing errors
5) Documentation: The final step in programming process is called documentation.
Documentation of a program consists a detailed procedure of operation of a program.
2) What is Top down Approach (or) Top down Design (or) Top down Programming?
A Module is a portion of program that also feels the definition of a program. These
subordinate modules can be further subdivided. Thus a hierarchical structuring of modules is
present with in the concept of modular programming. We have thus, superior modules and
subordinate module. Thus it is possible to design and develop a superior module before
designing subordinate module. This technique is known as top down approach. It is widely
accepted that top down approach provides visibility of the design and development process.
This makes the program less error-prone, and design and development activity takes less
time.
Thus to summarize, structured programming adopts the following 3 concepts that
helps to write good programs
1) structuring of control flow
2) Modular programming
3) Top down approach towards program design
The primary objective of structured programming is to increase readability and
understandability of a program. The structured program restricts transfer of control to
nearby places so that we don’t have to jump around while reading a program
Besides readability the other objectives that are achieved through structured
programming are as follows
2) The program becomes less error prone.
3) The programs become easily modifiable. This is the direct contribution of
modular programming.
4) The program development takes less time. This is again due to the simplicity of
methodology of structured programming.
(OR)
3) Explain the top down design approach?
It is one of the important design methodologies of programming. A program is
divided into different models or functions and there is one main program or model written
before all other models this main program or model can be called as a superior module and
all other models are called subordinate modules.
It is possible to design and develop their superior module before designing
subordinate modules this technique is know ass top down approach it is widely expected by
that top down approach provides visibility of the design and development process which
makes the program less error prom and less development time.
The goal of structured programming is to organized and displaying the programme design
and coding process. Process in order to prevent logical errors and to developed efficient
program. It consists of expression the logical of the program in term of three constructions
Sequence of two or more operations: it is the formalization of the idea of the program
statement expected in the order of their appearance.
Selection: it is the choice of alternative actions based on some conditions
(if, if else, if else if and etc)
Looping (or) ifferation: it s used to execute a piece of coin repeated while the condition
is true or some fixed no of times. Ex: for , while do while. Structured programming
breaking reducing the complicity of the program a structured may have the following
major characteristic
Modular Approach: it is the process of breaking up a programming problem into
logical parts called modules. It is of functional help in the modular design of the program
of the program. It reduces the program code make the debugging easier each functional
should be designed in such manner that is should be a logically self contained.
Step wise Refinement : The design stage consists of a sequences of requirement steps at
each step the given basic is broken into sub task until the subtask are simple enough to
be coded into a module with reliability
Top Down Design: It is one of the important design methodologies of programming. A
program is divided into different models or functions and there is one main program or model
written before all other models this main program or model can be called as a superior
module and all other models are called subordinate modules.
It is possible to design and develop their superior module before designing
subordinate modules this technique is know ass top down approach it is widely expected by
that top down approach provides visibility of the design and development process which
makes the program less error prom and less development time
4) What is an Algorithm?
Algorithm is one of the most central concepts in computer science. An algorithm is may
loosely be defined as an unambiguous (Clear cut) procedure for solving a problem. In turn, a
procedure is a finite sequence of well defined operations, each of which requires only a finite
account of storage and computer time.. Also, an algorithm should stop at finite time for any
input. Unambiguous procedure means a procedure that can be implemented on a specified
machine using a given language.
(OR)
An algorithm is set of sequential step usually written in ordinary English language with using
mathematical symbols or Algorithm is to solve the problem step by step processor with know
language.
a) Declaration: to define the data after the start keyword with using a declare keyword
is know as declaration part.
b) Input: To define a data name at declaration those must be assigned some value
through keyboard. In this input processing we must require the “ READ” statement
c) Logical processing: to define a data name and assign the value to be performed
some operation between the data name by using operator like “ + ,- , *, / , % , >, < ,
>/ , /< , # “ these are logical processing
d) Output processing: to solve the desire output format in this format the “ PRINTF”
statement is used.
Step1: Start
Step2: Read n ( n is value of factorial)
Step3: Initialise fact to 1; Initialise I to 1 which is control variable
Step4: Fact=Fact*i
Step5: i=i+1
Step6: if i>n then print Fact
Otherwise goto step4
Step7: Stop
What is a language?
Language is the communication media between two individuals. Every language is having a well
defined character set and a grammar.
What is an assembler?
Assembler is used to convert assembly level language program to machine level program.
THE HISTORY of C
Multics (Multiplexed Information and Computing Service) was an operating system developed in
the mid-60's by MIT that delivered a computing interface not seen before. It was the first
computing environment to deliver things like 1) dynamic linking 2) inter-process (really universal
daemon processes) communication 3) complete memory file mapping 4) hot-swappable devices
and 5) full security throughout the OS. Applications were written in an ancient language called
PL/1 and the OS ran on GE mainframes. The size, complexity and cost made multics and its
environment inhibiting for most companies/organizations to employ.
Unics (Uniplexed Information and Computing Service and later trademarked as UNIX) was an
answer to the cost and complexity of Multics. Ken Thompson decided to write UNIX on the much-
less expensive DEC PDP/7 (in comparison to the GE mainframes). Dennis Ritchie helped
Thompson on this project. Unics (UNIX) was able to support two simultaneous users; one of
which was Brian Kernighan the OTHER one is Dennis Ritchie
At the time writing assembly language applications was not only tedious but required an intimate
understanding of the target hardware. Ritchie (Kernighan and Thompson) wanted to develop a
language that was not only highly portable but still allowed for CPU-register manipulation,
memory management and (relatively) easy I/O (input/output).
For this reason the new language is to be developed. The C-language was developed in 1972 at
Bell laboratories by Dennis Ritchie. It is designed for the operating system called UNIX. 90% of
UNIX was written in ‘C’. It is derived from the ‘B’-language which is written by Ken Thompson at
Bell laboratories. It is excellent and efficient and general purpose programming language. By
using ‘C’, we can solve scientific, business, mathematical, research applications. The striking
feature of C-language is developing the system programs.
5. string-literal
6. Separators
Keywords:
These keywords have some standard pre-defined meaning in C-language. This meaning is
assigned by the compiler. The user cannot modify the meaning of keywords. There are 32
keywords in C-language they are
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
Identifier:
Identifier is the name used to uniquely identify an item in a program. It is used to represent
variables, constants, function names etc.
Rules:
1. The first letter must be an alphabet
2. Keywords are never used as identifiers.
3. Maximum length of an identifier is 8 characters.
4. No special characters are allowed except underscore (_).
5. Underscore should not be used at the beginning (or) ending of a variable name.
6. Identifiers names are case sensitive
Operators
Operator is a symbols used within an expression to perform specific operation on operands.
C has 15 simple operators ( ! % ^ & * - + = ~ | . < > / ? ), 11 compound assignment operators (
+= -= *= /= %= <<= >>= &= ^= |= == ), and 10 other compound operators ( -> ++ -- << >> <= >= !
= && || ).
Constants
Constant can be defined as the value of an identifier does not change while executing a program.
It is also called as literal. There are 3 types of constants. They are Integral constants, Floating
point constants, Character constants
Integer constants
It is used to represent positive or negative whole number without a fractional part.
There are 3 types of integer constants.
(a) Decimal Integer Constants: It contains decimal number 0 to 9. By default every
constant is a positive decimal constant.
(b) Octal Integer Constants: octal integer constants must begin with 0. It contains decimal
numbers 0 to 7. For example 07, 015, 05 etc
(c) Hexa Decimal Integer constants: Hexa decimal integer constants must begin with 0X.
It contains 0 to 9 numbers and A to F. Hear A=10, B=11, C=12, D=13, E=14, F=15.
For example 0x1, 0xA, 0X1F, 0X54 etc
Float constants:
It is used to represent positive or negative decimal number with an integer part, a decimal
point and a fractional part. For example 9.0, 12.13, 400.00 etc
Character constants:
Character constant is a single character that is enclosed within single quotes.
For example ‘A’, ‘9’, ‘B’, ‘+’, ‘x’, ‘0’, ‘ ’
{
}
In a C-program, preprocessor directives are executed before the C-program passes
through the compiler.
Mostly used preprocessor directives are: # include, # define
# include is mainly used for including necessary header files to our C-program
# define is used for macro definition
Global variables accessed by all the functions where as local variable are accessed within the
block. Every C-program has one (or) more functions. If a program has only one function, then it
should be the main function. Hence the execution of a C-program starts with the main function.
The main function has 2 parts.
They are: a) Declaration Part
b) Statement Part
The declaration part contains the declaration of local variables required for necessary operations
The following is an example C-program:
#include <stdio.h>
main ( )
{
int a,b,c;
Scanf(%d%d” , &a, &b);
C=a+b;
Printf (“Sum is %d” , c);
}
Output: Sum is C
C DATA TYPES
Structure Array
Union void Pointer
Enum Integral type Floating type Function
Void: this data type is introduce in ANSI – C. it is used to represent the following things
1) To specify the return type of a function when it is not returning any value.
2) To indicate an empty argument list to a function
Qualifier: qualifiers are used to extend the behavior of standard data type. There are two
qualifiers namely size and sign.
Size qualifier is used to extend the size of an existing data type Size qualifier: there are two size
qualifiers they are short and long. Short is used to decrees the size and ling is used to extend the
size to maximum. For example short int size is only 2 bytes irrespective of operating system. It is
not possible to apply size qualifier on char
Sign qualifier: sign qualifier used to make the data type as a signed number or unsigned
numbers. There are two sign qualifiers they are signed and unsigned. Unsigned qualifier is used
to make the number as a positive number. By default all number are positive. It is not possible to
apply sign qualifier on long, double.
Array:
Array can be defined as collection of similar data items which are stored in continuous sequence
to memory locations. Example int x[10]
Struct:
Struct can be defined as collection of dissimilar data items under a common name
Example struct test
{int a,
char b;
};
Union:
Union can be defined as collection of dissimilar data items under a common name
Enum: it stands for enumerated data type. It is used to attach name to numbers
String: collection of characters terminated by a null character
Function: a set of statements having well defined specific task. It is a sub program which
performs a specific task.
0 0 0
1 0 0
0 1 0
1 1 1
Let a=10, b=5 then the logical expression (a = = 10) && (b<a) gives the result as 1.
OR Operator: This operator gives the net result as false if and only if both the conditions have
false value. Otherwise the net result is true.
C1 C2 C1 C 2
0 0 0
1 0 1
0 1 1
1 1 1
Let a=7, b=12 then the logical expression (a < = b) (b>50) gives the result as 1.
NOT Operator: This is the only unary operator available in logical operators. This operator
negates the value of given condition. If the value of condition is false, the net result is 1 and if the
value of condition is true, the net result is 0.
C1 ! C1
0 1
1 0
Let a=10 then the logical expression! (a = = 10) gives the net result as 0.
Assignment Operator: A value can be stored in variables with the help of assignment operator.
= symbol denotes the assignment operator. The assignment operator has the following syntax.
Variable = expression;
For example a = 10; b = 20 ;x = a+b ;
Therefore x is assigned the value 30 which is the sum of a and b.
Compound assignment operator: it is a combination of operators. They contains +=,-=,*=./= etc
For example: a+=b a= a+b
a-=b a= a-b
a*=b a=a*b
a/=b a= a/b
Increment & Decrement Operators:
The increment operator (++) increments the value of the given variable by one and the decrement
operator (- -) decrements the value of the given variable by one.
For example a++ for a = a + 1 and a - - for a = a - 1
These operators are of two types :
(i) Pre increment / decrement
(ii) Post increment / decrement
1) Pre increment / decrement: Here the value of given variable is incremented first then this
incremented value is taken for the next operation.
Eg : (i) x = + + a ;
If the value of a=5, then in the above statement first a will be incremented by 1 (i.e) the
recent value of a is 6 which is assigned to the variable x.
(ii) x = - - a ;
If the value of a=5, then first a will be decremented by 1 (i.e) the recent value of a is 4
which is assigned to the variable x.
2) Post increment / decrement: Here the old value of the given variable will be operated with
the specified operation and later the increment/decrement is carried out.
Eg : (i) x = a + + ; let a=5
Here first the old value of a is assigned to x and then incrementation take place x=8, a=6
(ii) x = a - - let a = 5
In the same way, the old value of a is assigned to x and then decrementation take place
x=5, a=4.
Conditional operator or ternary operator:
The conditional operator are ? and : they are used for check the condition true or fale
Example: a > b ? printf( “big is A”): printf(“big is B”)
Bitwise operators
Different types of bitwise operator in C –language are 1. &bit wise and, 2 | bit wise or 3<< left shift
4>> right shift
For example a=3 the equal binary value is 0000 0000 0000 0010 then a<<1
Equal to 0000 0000 000 0100 it is equal to decimal 4
The scanf statement should have at least 2 parameters. First parameter is a control string which
includes format specification characters. Second parameter is the address of the variable. To get
the address of any variable, it must by preceded by ampersand sign (&).
Example: scanf (“%d” , &a);
In the above scanf statement, there are 2 parameters. One is the control string with %d
format. Specifier and another is an integer variable ‘a’ preceded by Ampersand Symbol.
The following example shows the way of reading multiple variables using a single scanf
statement.
# include <stdio.h>
main ( )
{
int a;
float b;
char ch;
double d;
scanf (“%d %f %c %lf” , &a, &b, &ch, &d);
}
Printf: -
C provides printf statement for displaying output data. Printf statement moves the data from
computer’s memory to the standard output device Monitor. The variable names are optional and
the variable name should not be preceded with ampersand symbol.
The general syntax of printf statement is as follows:
1. printf (string constant”);
2. printf (“control string”, list of variables);
Example:
1. # include <stdio.h>
main ( )
{
printf (“This is my first C- program”);
}
Output: This is my first C-program.
If statement:
Syntax: 1. if (condition) statement; // simple if statement
2. if (condition ) // if else statement
Statement
else
Statement
In if statement the value of the condition is equal to true or 1 then the statement in the true block
are executed and if the value of a condition is false the statements in the false block are
executed. In simple if statement only true block is available.
Switch
It is a multi-way branching statement. It is used to check multiple conditions against a list of case
values. When a match is found the statements under the case are executed
Syntax
Switch ( variable)
{
Case value1 : statement; break;
Case value2 : statement; break;
- - - -
- - - -
Case valuen : statement; break;
Default : statement;
}
Example
Switch (a)
{
Case 0: printf(“zero”); break;
Case 1: printf(“one”); break;
Default : printf(“ invalid “);
}
If no match is found the default is executed
For statement:
Syn for (initialisation; condition; step value ) Statement;
While statement:
Syntax initialization;
while (condition)
{statements;
Step value:
}
Example while (I ++> 0) Printf(“%d”,i);
If the condition value is true or 1 the statements in the while loop are executed and if the condition
is false the control come out of loop. The minimum number of times a loop executes is zero.
Exit control statements: in exit control statements first the control enters in to the loop and checks
the condition. If the condition value is equal to true or 1 repeats the statements other wise break
the loop. The minimum number of times the exit control loop executed is 1. For example do..
while.
Syntax initialization;
do
{
Statement;
Stepvalue:
} while (condition).
Unconditional statements:
Unconditional statements are used to transfer the control from one place to other with out any
condition. They are generally used to branch or termination process. For example goto, break,
continue, and exit;
the minimum number of times executed is The minimum number of times executed is
zero one
no semicolon at the end of while It must be terminated by a semicolon
The following is the general The following is the general of the do-while
syntax loop.
Initialization do
while (condition) {
{ :
: Body of loop
: } while (condition);
Increment,
Type of arrays: there are three types of arrays they are one dimension, double dimension and
multi dimension array
One Dimensional Arrays:-
A list of items can be given one variable name using only one subscript one- Dimensional
Array.
Syntax
datatype name[size]:
Where the datatype specifies the type of the element that will be contained in the array
such as int, float (or) char. Name indicates the name of the array.
Size indicates the maximum number of elements stored in the array.
For example:
float height [50];
Declares the ‘height’ to be an array containing 50 float elements
Initialising Arrays:
The array can be initialised with some initial values at the time of declaration is called
initialisation
For example
1. int num [6] = {2,4,12,5,9,3};
2. int a[ ] = {11, 12, 13, 14};
3. Float Press [ ] = {12.3, 14.5, 16.7, 18.9};
Note the following points from the above examples:
1. While initialising an array, it is optional to mention the size of the array. The size will be
automatically assumed by the compiler.
2. An uninitialised array contains garbage values as its initial values.
3. It is also possible to initialise an array by having the initial values less than the size.
Ex: int a[5] = {11, 12, 13};
Reading Arrays:
The following for loop explains the way of reading one - dimensional arrays :
int a[10];
:
for (i = 0; i<10;1++)
Scanf (“%d”, &a[i]);
Writing Arrays: (or) Displaying Arrays:
The following for loop explains the way of displaying the elements of the array:
int a[10];
for (i = 0; i<10;1++)
Printf (“%3d ”, &a[i]);
Double - Dimensional Arrays:
an array having both rows and columns. The following is the general syntax of declaring
a two - dimensional array:
datatype name [rows] [columns];
The following is an example of declaring a 3 x 3 matrix:
int a[3][3];
Sincerely the element at ith row and jth column can be referred as a [i] [j]
Initialising Arrays :
Like one-dimensional arrays, two-dimensional arrays can also be initialised at the time of
declaration.
The following are some examples of initialising 2D arrays:
1) int a [3] [3] = {
{11,12,13} ,
{14,15,16} ,
{17,18,19}
};
The following points are noted from the above initialisation :
(i) While initialising 2-D arrays, it is optional to specify the no.of rows.
(ii) As per the above example (1), a[0] [0] will be assigned with 11, a[0] [1] with 12 .........
a[2] [2] with 19.
(iii) As uninitialised 2-D array contains garbage values.
Reading 2-D Arrays:
The following nested for loops describes the way of reading 2-D arrays:
int a[3] [3] ;
:
for (i = 0; i<B; i++)
for (j = 0; j<B; j++)
Scant (“%d”, & a [i] [j]) ;
Writing 2-D Arrays:
The following nested for loops display the elements of 2-D array in the matrix format :
int a [3] [3] ;
:
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
printf (“%3d”, a[i] [j]),
printf (“\n”);
}
Write about string handling functions?
String can be defined as collection of characters terminated by a null character. It is an array of
characters.
Syntax char name [size] ;
Where name is the name of the string variable size determines the number of characters
that the string can hold.
When the compiler assigns a character string to a character array, it automatically
supplies a null character (‘\0’) which is denoted by “\0”. Hence the maximum no. of
characters required are size +1.
Reading Strings:
Scanf : sting can be read by using scanf with %s format. For example:
char S [15] ;
:
scanf (“%s”, S)
In the above scanf statement, a collection of characters can be taken into the string ‘S’.
The problem with the scanf function is that it terminates its input on the first space
character (or) first tab character (or) enter key. Therefore if the following line of text is
typed for the above scanf statement,
New York
Then, only the string ‘new’ will be taken into the string ‘S’. This is because the space
character after the word ‘New’ will terminate the string ‘S’. Hence the scanf statement
cannot read Multi Word Strings.
The scanf statement with %S format specifier does not need the usage of ampersand
symbol before the variable name. The name of the character array itself indicates the
address.
gets : gets is an unformatted input function and it can accept a string from the key board.
Syntax: gets (string name) ;
The gets function is able to read multi-word strings and it recognises only the enter key
as the terminating character for inputting a string. For example
char S [80] ;
:
gets (S) ;
String Initialisation : C permits a string to be initialised in the following ways :
1. char name [7] = “aditya” ;
char name [ ] = {‘a’, ‘d’, ‘i’, ‘t’, ‘y’, ‘a’, ‘\0’} ;
From the above examples, the following points are noted.
In the example 1 the sting is automatically teminated by null character
In the example 2 the string is terminated by ‘\0’ null character supplied by user
Writing string:
The ‘printf’ function with %s format specification is used to display the string.
The following is an example:
char name [7] = “aditya” ;
:
printf (“%S”, name) ;
In the above example, name is initialised with a string constant “aditya” and it can be
displayed by the printf statement as: aditya
String Handling Library Functions : (String-h)
The C-library supports a large number of string handling functions that can be used to
manipulate the strings in many ways.
The following are the most commonly used string library functions :
Library Functions Action
Strlen ( ) Finds the length of a given string
strcmp ( ) Compares the given 2 strings.
strcpy ( ) Copies are string to another
strcat ( ) Concatenates the given two strings
strrev ( ) Reverse the given string
Advantages of functions: -
1. Modular programming.
2. Program and function debugging is easier.
3. Division of work is simplified
4. Code reusability.
5. implement standard Library of functions
Function components:
Components of a function are
Function declaration or prototype
Function definition
Function call
Return
Function prototyping: -
The prototype tells the compiler function name, return data type, number of arguments and their
data types When a function call is occurred the compiler checks the function calls with its
prototype so that correct argument types are used. It should be declared as a first line of a main
program and must be terminated by semicolon (;).
The variable names are optional in prototype declaration. It should be terminated by semicolon.
Each parameter must be declared independently inside the parenthesis. A combined declaration
is not allowed.
Function call: -
A function gets life only when a call to the function is made. A function call is specified by the
function name followed by the arguments enclosed in parentheses and terminated by a
semicolon. The return type is not mentioned in the function call.
return:
The return statement is used to return the control back to the main program. It always returns
only one value at a time. There is no limitation for the number of return statements in a function
body. Once a return statement is executed control automatically transferred to the calling
program and leaves the remaining statements after the return statement in the function body.
Pointer initialization:
Syntax: pointer variable = & variable;
Pointers are always initialized with an address of any variable by using & symbol.
In this case, memory space is reserved to contain "hello" and then a pointer to the first character
of this memory block is assigned to variable x. The pointer x points to a sequence of characters
and can be read as an Array
Pointers to pointers
Pointers to pointer or ** pointers. ** Pointers are used to declare a double dimensional array.
Each * represents one dimension
The void pointer is a special type of pointer. It points to a value that has no type. It is used to
point any data type like integer, float, string etc.
Call by address:-
In call by address method the formal parameters must be a pointer type and they
receive the address of actual parameter.
Any changes to the formal parameters are automatically reflected back to the actual
parameters in the main program.
It is possible to return more than one value
The address can be generated by using address operator &
Thus the complete program of swapping 2 numbers using call by address is as follows.
From the above example, it is clear that the main() function can display the swapped values of a
and b
Benefits: -
1. Inline function makes a program to run faster, because function call and return is
eliminated
2. For the small functions it is always convenient to use inline functions.
Disadvantages: -
1. Inline functions require more memory because they expanded while compiling the
program
2. it is not good for function if the size of a function is increased
3. The inline key word sends a request but not a command to the compiler. Hence the
compiler can ignore the request if the function definition is too long
Sample run: in the above program the value of n = 3 the expected output is 6
main()
{
Incr();
Incr();
Incr();
}
Incr()
{
static n;
printf(“%d”,n++);
}
Output: 0,1,2
Structure Union
It can be defined as collection of dissimilar It can be defined as collection of dissimilar
data items data items
The size of the structure is equal to the sum The size of the union is equal to the
of the sizes of the individual data members maximum size of the data member of the
union
The first statement declares the variable fp as pointer to the data type FILE.
The fopen function contain two parameters they are filename and mode
The modes are
r open for read only
w open for write only
a open for append only
Closing file
The following is the general form of closing a file
Syntax: fclose(fp);
fprintf:
The general form of fprintf statement is
Syntax fprintf(fp,”format string”, variable);
Example fprintf(fp,”%d%s”,rno, name);
Here rno and name values are write into the file through the file pointer fp
fputc
The general form of fpuc statement is
Syntax fputc(ch,fp);
Example fputc(‘a’,fp);
Here ‘a’ value write into the file through the file pointer fp
fscanf:
The general form of fscanf statement is
Syntax fscanf(fp,”format string”, variable);
Example: fscanf(fp,”%d%s”,&rno,&name);
In this example the rno and name values are read form file using file pointer fp
fgetc
The general form of fgetc statement is
Syntax ch= fgetc(fp);
Example ch=fputc(fp);
Here character ch value read form file through the file pointer fp
What is preprocessor?
#is the preprocessor directive which is used to declare header file. They are execture before the
main function
Example: #include <stdio.h> which contains printf() and scanf ()
#include<math.h> which contains sqrt(), pow()
#include<conio.h> which contains clrscr()