Lab Manual
Lab Manual
Introduction
Control Unit
Arithmetic Logic Unit (ALU): Executes all arithmetic and logical operations. Arithmetic
calculations like as addition, subtraction, multiplication and division. Logical operation like
compare numbers, letters, or special characters
Registers : Stores the data that is to be executed next, "very fast storage area".
Buses:
The buses on a computer system are sets of wires that carry information to or from memory or
I/O devices. They may be uni-directional (data travels one way) or bi-directional (data travels
both ways).
Buses can be seen on the computer motherboard as parallel metal tracks. It connects physical
components such as cables, printed circuits, CPU, Memory, Peripherals etc., for sharing of
Information and communication with one another. The purpose of buses is to reduce the
number of "pathways" needed for communication between the components, by carrying out all
communications over a single data channel. Fig 3 shows the different types of buses.
Types of buses:
This equates to 256 unique memory addresses. A 16 bit bus can address 65536 unique
addresses and so on.
Data Bus:
● The data bus carries the data that is to be written or has been read from memory.
● It is a bidirectional bus as it can carry data to or from memory.
● The width of the data bus is directly related to the largest number that the bus can carry.
For example an 8 bit bus can represent 2 to the power of 8 unique values. This equates
to the numbers 0 to 255. A 16 bit bus can carry the values 0 to 65535 and so on.
Control Bus:
● The control bus carries signals that control the actions of the computer.
● For example one line of the control bus may be the read/write line. If the wire is low
(no electricity flowing) then the memory is read. If the wire is high (with electricity
flowing) then the memory is written.
Mother Board
A motherboard is one of the most essential parts of a computer system. It holds together many
of the crucial components of a computer, including the central processing unit (CPU), memory
and connectors for input and output devices. Fig 4 shows the picture of motherboard.
The base of a motherboard consists of a very firm sheet of non-conductive material, typically
some sort of rigid plastic. Thin layers of copper or aluminum foil, referred to as traces, are
printed onto this sheet. These traces are very narrow and form the circuits between the various
components. In addition to circuits, a motherboard contains a number of sockets and slots to
connect the other components.
● A CPU socket - the actual CPU is directly soldered onto this socket. Since high speed
CPUs generate a lot of heat, there are heat sinks and mounting points for fans right next
to the CPU socket.
● A power connector to distribute power to the CPU and other components.
● Slots for the system's main memory, typically in the form of DRAM chips.
● A chip forms an interface between the CPU, the main memory and other components.
On many types of motherboards this is referred to as the Northbridge. This chip also
contains a large heat sink.
● A second chip controls the input and output (I/O) functions. It is not connected directly
to the CPU but to the Northbridge. This I/O controller is referred to as the Southbridge.
The Northbridge and Southbridge combined are referred to as the chipset.
● Several connectors, which provide the physical interface between input and output
devices and the motherboard. The Southbridge handles these connections.
● Slots for one or more hard drives to store files. The most common types of connections
are Integrated Drive Electronics (IDE) and Serial Advanced Technology Attachment
(SATA).
● A Read-only memory (ROM) chip, which contains the firmware, or startup instructions
for the computer system. This is also called the BIOS.
● A slot for a video or graphics card. There are a number of different types of slots,
including Accelerated Graphics Port (AGP) and Peripheral Component Interconnect
Express (PCIe).
Chipset :
The actual function of a chipset is to communicate between all components of the modern PC,
or, to put it in other words, the chipset is the infrastructure. The chipset contains numerous
components, and moreover, it makes various interfaces available for connecting additional
components (PCI, USB, AGP, IDE, etc). As a rule, the chipset consists of two units, the
Northbridge and the Southbridge. The reason that it is made of two units instead of one is that
it's difficult to integrate all components onto a single chip. The use of two chips also allows for
different combinations of Southbridge and Northbridge chips. Today, most manufacturers have
a small building-block type of system from which the motherboard makers can choose
components to suit customer requirements.
Network interface card (NIC): A network interface card (NIC) is a circuit board or card that
is installed in a computer so that it can be connected to a network.
A network interface card provides the computer with a dedicated, full-time connection to a
network. Personal computers and workstations on a local area network (LAN) typically contain
a network interface card specifically designed for the LAN transmission technology.
Computer Components:
A computer system consists of both hardware and information stored on hardware. Information
stored on computer hardware is often called software.
The hardware components of a computer system are the electronic and mechanical parts.
Computer hardware is the collection of physical elements that constitutes a computer system.
Computer hardware refers to the physical parts or components of a computer such as the
monitor, mouse, keyboard, computer data storage, hard drive disk (HDD), system unit (graphic
cards, sound cards, memory, motherboard and chips), etc. all of which are physical objects that
can be touched.
Hardware:
The major hardware components of a computer system are:
1. RAM
2. ROM
1. RAM (Random Access Memory) – It stands for Random Access Memory. RAM is known
as read /writes memory. It generally refereed as main memory of the computer system. It is a
temporary memory. The information stored in this memory is lost as the power supply to the
computer is switched off. That’s why RAM is also called “Volatile Memory”.
a) Static RAM- Static RAM also known as SRAM ,retain stored information as long as the
power supply is ON. SRAM are of higher coast and consume more power .They have higher
speed than Dynamic RAM
b) Dynamic RAM– Dynamic RAM also known as DRAM, its stored information in a very
short time (a few milliseconds) even though the power supply is ON. The Dynamic RAM are
cheaper and moderate speed and also they consume less power.
2. ROM (Read Only Memory) – It stands for Read Only Memory.ROM is a Permanent Type
memory. Its content are not lost when power supply is switched off. Content of ROM is decided
by the computer manufacturer and permanently stored at the time of manufacturing. ROM
cannot be overwritten by the computer. It is also called “Non-Volatile Memory”.
Input Devices :Input device is any peripheral (piece of computer hardware equipment to
provide data and control signals to an information processing system such as a computer or
other information appliance. Input device Translate data from form that humans understand to
one that the computer can work with. Most common are keyboard and mouse.
Output devices: Every computer system will need to have a way of displaying information or
printing information out so that it is useful to humans. There needs to be, therefore, some
‘output devices’. A very useful output device is a VDU (or Visual Display Unit). Another
handy one that allows you to produce ‘hardcopy’ (i.e. a printout on paper) is a printer.
Software:
Software is a set of programmes/commands designed to perform a well-defined task.
Software systems can be divided into two major classes:
• System software: Helps run the computer hardware and computer system itself. System
software includes operating systems, device drivers, diagnostic tools and more. System
software is almost always pre-installed on your computer.
• Application software: Allows users to accomplish one or more tasks. It includes word
processing, web browsing and almost any other task for which you might install software.
(Some application software is pre-installed on most computer systems.)
Software is generally created /written in a high-level programming language, one that is (more
or less) readable by people. These high -level instructions are converted into "machine
language" instructions, represented in binary code, before the hardware can "run the code".
Utility Software: is system software designed to help analyze, configure, optimize or maintain
a computer. Utility software, along with operating system software, is a type ofsystem software
used to support the computer infrastructure, distinguishing it from application software which
is aimed at directly performing tasks that benefit ordinary users. PDF Creator,File Archiving
and PDF Converters are commonly used utility software.
Operating System:
An Operating System (OS) is system software that controls and supervises the hardware
components of a computer system and it provides the services to computer users. Also called
as Resource Manager that manages the resources such as CPU, Memory, I/O devices,
Job/Task/Process etc., a computer cannot run without it. The major functions of OS includes:
CPU Management, Memory Management, File Management, Device Management,
Process/Task/Job Management and Security Management.
The primary goal of an OS is to make the computer system convenient and efficient to use. An
OS ensures that the system resources (such as CPU, memory, I/O devices, etc) are utilized
efficiently. For example, there may be many programs residing in the main memory. Therefore,
the system needs to determine which programs are active and which need to wait for some I/O
operation.
Batch Processing OS: The data is collected into a group called batch and provides only one
batch (one after another) of jobs as input to the computer system at a time. The jobs in a batch
are processed on first come first serve basis. In this type, the process takes place at specified
time intervals i.e. weekly or monthly without user interaction. E.g. Punch cards were using to
store the data in batch processing and in payroll preparation in a business batch processing was
helpful.
Single user and single tasking OS: The OS that allows only one program to execute at a time
is called single user single tasking operating system. Using this operating system user can do
only one task at a time. E.g. DOS (Disk Operating System).
Single user and multi tasking OS: The OS that allows a single use to perform more than one
task at a time is called single user multi tasking operating system. While working with the Ms-
Word user can perform other work like print a document, listen music.E.g. Windows-XP,
Windows Vista, Windows – 7, etc.
Multi user and multitasking OS: The OS that allows two or more users to use a main
computer system to do more than one task is called multiuser and multitasking operating
system.E.g. UNIX is a multiuser and multitasking operating system.
Multiprocessing OS: The OS that allows multiple programs to be executed by multiple CPUs
(Processors) is called multiprocessing operating system. Super and main frame computers have
more than one CPU and multiprocessing operating system.
Real Time Operating System (RTOS): The OS that is used for real time applications and to
carry out certain calculations within the specified time constraint. This OS is used in
applications such as mobile phones, supporting systems in hospitals, nuclear power plants, oil
refining, chemical processing, environmental applications and air -traffic control systems,
disaster management etc.,
Virtual machine OS: Allows several users of a computer system to operate as if each has the
only terminal attached to the computer.
Flowchart:
The various types of geometric shapes, arrows and symbols used while drawing the flow chart
are called flowchart symbols. The symbols used and the meaning associated with each symbol
are shown below in Fig 6.
Procedure: This program takes an arithmetic operator +,-,*,/,% and two operands from the user and
performs the calculation on the two operands depending upon the operator entered by the user.
Input: An operator and two operands.
Expected Output: Performs calculation and display result depending upon the operator.
ALGORITHM
Algorithm Calculator
Step 1: Start
Step 2: Read num1 and num2
Step 3: Enter the operator
Step 4: Evaluate operator wit case statements
Step 4.1: case ‘+’ : result = num1+num2
goto step 6
Print result
Step 4.2: case ‘-’ : result = num1-num2
goto step 6
Print result
Step 4.3: case ‘*’ : result = num1*num2
goto step 6
Print result
Step 4.4: case ‘/’ : result = (float)num1/(float)num2
goto step 6
Print result
Step 4.5: case ‘%’ : result = num1%num2
goto step 6
Print result
Step 5: Enter operator is invalid then
Print “Invalid Operation”
Step 6: Print result
Step 7: Stop
FLOWCHART
#include <stdio.h>
int main()
{
int num1, num2;
float result=0;
char ch;
printf("Choose operation to perform (+,-,*,/,%): ");
scanf(" %c", &ch);
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
switch(ch)
{
case '+':result=num1+num2;
break;
case '-':result=num1-num2;
break;
case '*': result=num1*num2;
break;
case '/':result=(float)num1/(float)num2;
break;
case '%': result=num1%num2;
break;
default: printf("Invalid operation.\n");
exit(0);
}
printf("Result: %d %c %d = %f\n",num1,ch,num2,result); //display output on screen
Procedure: The equation in the form ax2+bx+c=0 is called quadratic equation. Read the
coefficients a,b,c and calculate discriminant. Based on the discriminant value, calculate roots and
print them with suitable messages.
Expected Output: This program computes all possible roots for a given set of coefficients with
appropriate messages. The possible roots are: Real and Equal roots, Real and distinct roots,
imaginary roots.
ALGORITHM
Quadratic_Equation [This algorithm takes three coefficients as input and compute the roots]
Program:
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,d,rpart,ipart,root1,root2;
printf("Enter three co-efficient\n");
scanf("%f%f%f",&a,&b,&c);
}
else if(a==0)
{
printf(“Linear Equation\n”);
root1=-c\b;
printf(“Root=%f\n”,root1);
}
else
{
d=(b*b)-(4*a*c);
if(d==0)
{
printf("The roots real and equal\n");
root1= -b/(2*a);
root2=root1;
printf("The roots are root1=%.3f and root2=%.3f\n",root1,root2);
}
else if(d>0)
{
printf("The roots are real and distinct\n");
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
printf("The roots are root1=%.3f and root2=%.3f\n",root1,root2);
}
else
{
printf("The roots are imaginary\n");
rpart=-b/(2*a);
ipart=sqrt(fabs(d))/(2*a);
printf("The first root root1=%.3f+i%.3f\n",rpart,ipart);
printf("The second root root2=%.3f-i%.3f\n",rpart,ipart);
}
}
}
3. An electricity board charges the following rates for the use of electricity: for the first 200
units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs 1
per unit. All users are charged a minimum of Rs. 100 as meter charge. If the total
amount is more than Rs 400, then an additional surcharge of 15% of the total amount is
charged. Write a program to read the name of the user, the number of units consumed,
and print out the charges.
Expected Output: This program checks all else if ladder conditions as per number of units
consumed by consumer and display appropriate output
ALGORITHM:
Step 1: Start
Step 2: Read name & unit
Step 3: if(unit <=200)
charge = unit *0.8+ 100
else if(unit<=300)
charge=(unit-200) *0.90+160;
else if(unit>300)
charge=(unit-300) *1+250;
if(charge>=400)
charge=charge + charge*0.15;
Flowchart:
PROGRAM
#include <stdio.h>
int main()
{
char name[10];
float unit, charge, min=100 ;
printf("Enter your name and unit Consumed:\n");
scanf("%s%f",name, &unit);
if(unit<=200)
charge=unit*.80+min;
else if(unit<=300)
charge=(unit-200)*0.90+160+min;
else
{
if(unit>300)
charge=(unit-300) *1+250+min;
}
if(charge>=400)
charge=charge + charge*0.15;
4. Write a C Program to display the following by reading the number of rows as input,
1
121
12321
1234321
Procedure: Input n rows, display numbers in ascending order till middle and reverse the order when
reaches the middle.
Input: Number of rows
Expected Output: For each row after it reaches the corresponding element which matches with the row
number, the reversing of elements happens.
ALGORITHM:
Step 1: Start
Step 2: Read i, j, n
Step 3: if j=0; j<=n-1; j++
Display blank spaces
if j=1;j<=i;j++
Display numbers in ascending order up to middle
If j=i-1;j>=1;j--
Display number in reverse order after middle
Step 4: Display the result
Step 5: Stop
FLOWCHART
PROGRAM
#include <stdio.h>
void main()
{
int i,j,n;
printf("Input number of rows : ");
scanf("%d",&n);
for(i=0;i<=n;i++)
I & II-Semester, BPOPS13/23 Page 22 | 42
RV Institute of Technology & Management®
{
/* print blank spaces */
for(j=0;j<=n-1;j++)
printf(" ");
/* Display number in ascending order upto middle*/
for(j=1;j<=i;j++)
printf("%d",j);
/* Display number in reverse order after middle */
for(j=i-1;j>=1;j--)
printf("%d",j);
printf("\n");
}
}
Procedure: Input N array elements and to find whether element is present or not.
Input: Array elements.
Expected Output: Successful search or unsuccessful search.
ALOGRITHM
Algorithm bubble_sort
Step 1: Start
Step 2: Read n
Step 3: Repeat for i=0 to n-1
Read a[i]
Step 4: read key
Step 5: Initialize low =0 high = n-1
Step 6: Repeat through step 6 while (low <= high)
mid = (low+ high)/2
if(key==a[mid])
found=1
else if(key>a[mid])
low=mid+1
else
high=mid-1
end while
Step 7: if(found ==1)
print “Item found”
else
print” Item not found”
Step 8: Stop
FLOWCHART:
PROGRAM
#include<stdio.h>
int main()
{
int i,n,a[10],mid,low,high,key, found=0;
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(key==a[mid])
{
found=1;
exit(0);
}
else if(key>a[mid])
low=mid+1;
else
high=mid-1;
}
if(found ==1)
printf(“Item found in position : %d”,mid+1);
else
printf("\n Item not found\n");
}
ALGORITHM
PROGRAM
#include<stdio.h>
#include<conio.h>
int main()
{
int m,n,p,q,i,j,k,a[10][10],b[10][10],c[10][10];
printf("Enter the size matrix A \n");
scanf("%d%d",&m,&n);
printf("Enter the size matrix B \n");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf(“Matrix multiplication is not possible\n”);
}
else
{
printf("Enter the elements of matrix A \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf ("%d",&a[i][j]);
}
printf("Enter the elements of matrix B \n");
for(i=0;i<p;i++)
{
` for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
printf(‘A-matrix is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
7. Compute sin(x)/cos(x) using Taylor series approximation. Compare your result with the built-
in library function. Print both the results with appropriate inferences.
ALGORITHM
Algorithm: Sine_series
Step 1:[Start the algorithm]
Start
Step 2:[Read the value of x]
Read x
Step 3:[Initialize the variables]
x1x;
xx*(3.142/180.0)
Step 4;[Read the value of no of terms]
Read n
Step 5:[Initialize the variables]
termx;
sinxterm;
Step 6:[Repeat the following steps for n=1 to n terms
den2*n*(2*n+1)
term-term*x*x/den;
sum=sum+term;
Step 7:Print the result
sum of sine series=sum
sum using library function=sin(x)
Step 8: Stop
FLOWCHART
x←degree*(PI/180)
nume←x
fact←1
sum←x
Term← nume/fact
nume← -nume*x*x
fact← fact*i *(i+1)
sum←sum+term
i-i+2
if
term>=
predefined sine
Program:
#include<stdio.h>
#include<math.h>
#define PI 3.142
int main()
{
int i, degree;
float x,sum=0,term,nume,fact;
printf("Enter value of degree \n");
scanf("%d", °ree);
x=degree*(PI/180);
nume=x;
fact=1;
i=2;
do
{
term= nume/fact;
nume=-nume*x*x;
fact=fact*i*(i+1);
sum= sum+term;
i=i+2;
}while(fabs(term)>=0.00001);
printf("The sine of %d is %.3f",degree,sum);
printf("Using inbuilt function sin(%d) is %.3f",degree,sin(x));
ALGORITHM
Bubble sort
Step 1: [Start of the algorithm]
Start
Step 2: [Read the size of the array]
read n
Step 3: [Read the array elements]
Repeat for i0 to n-1
read a[i]
Step 4: [Print the given array]
Repeat for i0 to n-1
print a[i]
Step 5: Repeat through step 5 for i1 to n-1
Repeat for j0 to n-i
if(a[j]>a[j+1])
tempa[j]
a[j] a[j+1]
a[j+1] temp
Step 5: [Print the sorted array]
Repeat for i 0 to n-1
print a[i]
Step 6 :[terminate the algorithm]
Stop
FLOWCHART
Program:
#include<stdio.h>
int main()
{
int a[100],n,i,j,temp;
9. Write functions to implement string operations such as compare, concatenate, string length.
Convince the parameter passing techniques.
ALGORITHM
Step 1: Start
Step 2: read string s1 & s2
Step 3: [call function strlength()]
i.e length =strlength
Step 4: Display length 1 and length 2
Step 5: [call function compare string]
if(compare_ string(s1,s2)==0)
print” equal strings”
else
print”unequl strings”
Step 6: call function concatenate
if(concatenate(s1,s2))
Step 7: print”concatenate string”
Step 8: Stop
Algorithm String_length()
Step 1: Start
Step 2: repeate step 2 through while(s1[i]!=’\0’)
i++
return i
end while
Step 3: Stop
Algorithm String_compare()
Step 1: Start
Step 2: repeatr step 2 trough while(s1[i]==s2[i])
if(s[i]==’\0’|| s2[i]==’\0’)
break
i++
end while
Algorithm String_concatenate()
Step 1: Start
Step 2: Initilize i=0
Step 3: repeate step 3 through while (s1[i]!=’\0’)
i++
end while
Step 4: initialize j=0
Step 5: repeate step 5 through while(s2[i]1=’\0’)
s1[i]=s2[j]
i++ j++
end while
Step 6: s1[i]=’\0’
Step 7: Stop
PROGRAM
#include <stdio.h>
int main()
{
char s1[100], s2[100];
printf("Input a string1\n");
gets(s1);
printf("Input a string2\n");
gets(s2);
if (compare_strings(s1, s2) == 0)
printf("Equal strings.\n");
else
printf("Unequal strings.\n");
concatenate(s1, s2);
printf("String obtained on concatenation: \"%s\"\n", s1);
i++;
}
if (s1[i] == '\0' && s2[i] == '\0')
return 0;
else
return 1;
}
10. Implement structures to read, write and compute average- marks and the students scoring
above and below the average marks for a class of N students.
ALGORITHM
Step 1: Start
Step 2: create the structure student with fields usn, name and marks and structure variable s[10].
Step 3: Initialize the variables countav=0, countbv=0
Step 4: read the number of students ‘n’
Step 5: read the value of usn name & marks for n number of students using structure variable
s[i] for i=0 to n-1
Step 6: Display the details
Step 7: repeat for i=0 to n-1
Compute the sum of students
Step 8: compute the average
Step 9: repeat for i=0 to n-1
if(s[i].marks >= average)
printf” total number of students above average”
else
printf” total number of students below average”
Step 10: Stop
PROGRAM
#include <stdio.h>
struct student
{
char usn[50];
char name[50];
int marks;
}
int main()
{
struct student s[10];
int i,n,countav=0,countbv=0;
float sum,average;
printf("Enter number of Students\n");
scanf("%d", &n);
printf("Displaying Information:\n\n");
for(i=0; i<n; i++)
{
printf("\nUSN: %s\n",s[i].usn);
printf("Name: %s\n ", s[i].name);
printf("Marks: %d",s[i].marks);
printf("\n");
}
for(i=0;i<n;i++)
{
sum=sum+s[i].marks;
}
average=sum/n;
printf("\nAverage marks: %f",average);
for(i=0;i<n;i++)
{
if(s[i].marks>=average)
countav++;
else
countbv++;
}
printf("\nTotal No of students above average= %d",countav);
printf("\nTotal No of students below average= %d",countbv);
}
11. Develop a program using pointers to compute the sum, mean and standard deviation of all
elements stored in an array of N real numbers.
ALGORITHM
Step 1: Start
Step 2: read n
Step 3: read for i=0 to n-1
Read a[i]
Step 4: prt=a
Step 5: repeat for i=0 to n-1
sum = sum+*prt
prt++
Step 6: mean=sum/n
Step 7: ptr=a
Step 8: repeat for i=0 to n-1
sumstd=sumstd+pow((*ptr-mean),2)
ptr++
Step 9: std=sqrt(stdsum/n)
Step 10: print mean sun and standard deviation
Step 11: Stop
FLOWCHART
Program:
#include<stdio.h>
#include<math.h>
int main()
{
float a[10],*ptr,mean,std,sum=0,sumstd=0;
int n,i;
printf("Enter the number of elements\n");
scanf("%d",&n);
printf("Enter array elements\n");
for(i=0;i<n;i++)
{
scanf("%f",&a[i]);
}
ptr=a;
for(i=0;i<n;i++)
{
sum=sum+*ptr;
ptr++;
}
mean=sum/n;
ptr=a;
for(i=0;i<n;i++)
{
sumstd = sumstd + pow((*ptr-mean),2);
ptr++;
}
std=sqrt(sumstd/n);
printf("Sum=%.3f\t",sum);
printf("Mean=%.3f\t",mean);
printf("Standard Deviation =%.3f\t",std)
12. Write a C program to copy a text file to another, read both the input file name and target file
name.
ALGORITHM
Step 1: Start
Step 2: read *ptr1, *ptr2
Step 3: Input source file name fname1 and print fptr1
Step 4: Check if fptr1= NULL? If yes Print file doesn’t found or Error in opening if
no Input new file name fname2 and print fptr1
Step 5: Check if fptr2= NULL? If yes Print file doesn’t found or Error in opening if no
Print fclose(fptr1) fclose(fptr2) getchar()
Step 6: while exit1 print ch=fgetc(fptr1)
Step 7: check if ch==EOF if yes print fclose(fptr1) fclose(fptr2) getchar()
else Print fputc(ch, fptr2)
Step 8: print results
Step 9: Stop
PROGRAM
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr1, *fptr2;
char ch, fname1[20], fname2[20];
fptr1=fopen(fname1, "r");
if(fptr1==NULL)
{
printf(" File does not found or error in opening.!!");
exit(1);
}
printf(" Input the new file name : ");
scanf("%s",fname2);
fptr2=fopen(fname2, "w");
if(fptr2==NULL)
{
printf(" File does not found or error in opening.!!");
fclose(fptr1);
exit(2);
}
while(1)
{
ch=fgetc(fptr1);
if(ch==EOF)
{
break;
}
else
{
fputc(ch, fptr2);
}
}
printf(" The file %s copied successfully in the file %s. \n\n",fname1,fname2);
fclose(fptr1);
fclose(fptr2);
getchar();
}