STRUCTURED PROGRAMMING IN C Module-VI
Introduction to structure
Definition of structure:
Structures are user defined data types. Structure is a group of related
variables of different data types under a single name. They provide a way
to create complex data types.
Syntax to Define a Structure in C:
struct StructureName
{
Data_type1 member_name1;
Data_type2 member_name2;
Data_type2 member_name2;
}one or more structure variables;
Keyword struct: Structure can be defined using “struct” keyword. The
keyword “struct” is used at the beginning of a structure in C.
StructureName: This is the name of the structure which is specified after
the keyword struct. It is identifier of structure.
Structure members or structure fields:
The variables declared inside a structure are called members or fields.
They represent the individual attributes of structure describes.
Structure Variables:
A structure definition acts as a blueprint; it does not allocate memory.
Memory is allocated only when a variable of that structure is created.
How to declare a structure variable
Structure variables allocate memory separately to all data members of the
structure. There are two ways to create a structure variable in C.
Declaration of Structure Variables with Structure Definition
This way of declaring a structure variable is suitable when there are few
variables to be declared.
Example:
struct Student
{
int roll_number;
char name[20];
} s1, s2; // structure variables
The structure variables are declared at the end of the structure definition,
right before terminating the structure. In the above example, s1 and s2
are the variables of the structure Student. These variables will be
allocated separate copies of the structure’s data members that are-
roll_number, name and percentage.
Declaration of Structure Variables Separately
This way of creating structure variables is preferred when multiple
variables are required to be declared. The structure variables are declared
outside the structure definition.
Example
struct Student
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 1
STRUCTURED PROGRAMMING IN C Module-VI
{
int roll_number;
char name[20];
};
int main()
{
struct Student s1, s2; // structure variables;
}
Initialize a structure or Initialize Structure members
Structure members cannot be initialized like other variables inside the
structure definition. This is because when a structure is defined, no
memory is allocated to the structure’s data members at this point.
Memory is only allocated when a structure variable is declared. Consider
the following code snippet.
Example :
struct student
{
int roll_number=10;//COMPILER ERROR: cannot initialize members here.
char bane[20]=”Kumar”;//COMPILER ERROR:cannot initialize members
here.
};
A compilation error will be thrown when the data members are initialized
inside the structure.
To initialize a structure’s data member, create a structure variable. This
variable can access all the members of the structure and modify their
values. Consider the following example which initializes a structure’s
members using the structure variables.
struct student
{
introll_number;
char name[20];
};
int main()
{
structstudent s1; // structure variables;
s1.roll_number =101;
strcpy([Link],”Kumar”);
}
In the above example, the structure variable s1 is modifying the data
members of the structure. The data members are separately available to
s1 as a copy. Any other structure variable will get its own copy, and it will
be able to modify its version of the length and breadth.
Different Ways to initialize Structure data members:
WAY-1:
struct student
{
introll_number;
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 2
STRUCTURED PROGRAMMING IN C Module-VI
char name[20];
};
struct student
{
struct student s1;
s1.roll_number = 101;
strcpy([Link],“Kumar”);
};
WAY – 2:
struct student
{
introll_number;
char name[20];
}s1 = {101, “Kumar”};
How to Access Structure members
The members of a structure are accessed outside the structure by the
structure variables using the dot operator(.)or ““ operator. The following
syntax is used to access any member of a structure by its variable:
Syntax
[Link];
structVariablestructMember;
Memory Representation of Structure:
Always, contiguous(adjacent) memory locations are used to store
structure members in memory. Consider below example to understand
how memory is allocated for structures.
There are 3 members declared for structure in above program. In 64 bit
compiler, 4 bytes of memory is occupied by intdatatype. 1 byte of memory
is occupied by char datatype, but it is a character array, so it occupies 8-
bytes and 4 bytes of memory is occupied by float datatype. So finally
above structure occupies 16-Bytes of memory for Student Structure.
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 3
STRUCTURED PROGRAMMING IN C Module-VI
Nested Structures
Nested structures in C refer to the concept of declaring one structure as a
member of another structure. This allows for the creation of more complex
and organized data structures, where related information can be logically
grouped together.
Types of Nested Structures in C
1).Embedded Structure
2). Separate Structure.
1). Embedded Structure:
In programming, an embedded structure, also known as a nested
structure, refers to the declaration of one structure within another. This
allows for the logical grouping of related data, enhancing code
organization and readability.
struct[Outer Structure_Name]
{
data_member1;
data_member_2;
…….
struct[inner_structure_name]
{ // Inner structure defined inside
data_member_1;
data_member_2;
} inner_stru_var_name; // Variable of the inner structure
}outer_stru_var_name;
Example Program for Direct Nesting Structure:
Q). Create a Student Outer structure with members Name,
Roll_Number, Name, and Address inner structure with data
members city &pincode. Write a C program to read and display
the information of a Student and address structure using Direct
Nesting Structure.
Source Code:
#include <stdio.h>
struct Student
{
int roll;
char name[50];
struct Address
{
char city[30];
int pincode;
} addr; // Named, directly nested structure
}s;
int main()
{
printf("Enter Roll Number: ");
scanf("%d", &[Link]);
printf("Enter Name: ");
scanf(" %[^\n]", [Link]);
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 4
STRUCTURED PROGRAMMING IN C Module-VI
printf("Enter City: ");
scanf(" %[^\n]", [Link]);
printf("Enter Pincode: ");
scanf("%d", &[Link]);
printf("\n--- Student Details ---\n");
printf("Roll No : %d\n", [Link]);
printf("Name : %s\n", [Link]);
printf("City : %s\n", [Link]);
printf("Pincode : %d\n", [Link]);
return 0;
}
2). Separate Structure in nested Structures:
In C programming, a "separate structure" approach to nested structures
involves defining the inner structure independently and then including it
as a member within the outer structure. This differs from "embedded
structures," where the inner structure is defined directly inside the outer
structure.
SyntaxSeparate Structure:
struct Inner_Structure_name
{
data_member_3;
data_member_4;
};
struct Outer_Structure_name
{
data_member_1;
data_member_2;
struct Inner_Structure_name Inner_structure_var_name;
//Nested structure (separate)
};
Example Program:
Write a C program to store and display employee details using
Separate structures.
#include <stdio.h>
struct Address
{
char city[20];
int pin;
};
struct Employee
{
int id;
char name[50];
struct Address addr; // Nested separate structure
};
int main()
{
struct Employee emp;
// Input
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 5
STRUCTURED PROGRAMMING IN C Module-VI
printf("Enter employee ID: ");
scanf("%d", &[Link]);
printf("Enter employee name: ");
scanf(" %[^\n]", [Link]);
printf("Enter city: ");
scanf(" %[^\n]", [Link]);
printf("Enter pin code: ");
scanf("%d", &[Link]);
// Output
printf("\n--- Employee Details ---\n");
printf("ID : %d\n", [Link]);
printf("Name : %s\n", [Link]);
printf("City : %s\n", [Link]);
printf("Pin : %d\n", [Link]);
return 0;
}
Array within the structure
C programming, a structure can contain different data types — including
arrays.
This allows you to store multiple elements (like marks, name, scores)
inside a single structured variable.
#include <stdio.h>
struct Student
{
int roll;
char name[20];
int marks[5];
};
int main()
{
struct Student s1;
int i;
printf("Enter roll number: ");
scanf("%d", &[Link]);
printf("Enter name: ");
scanf("%s", [Link]);
printf("Enter marks of 5 subjects:\n");
for(i = 0; i < 5; i++)
scanf("%d", &[Link][i]);
// Output
printf("\n--- Student Details ---\n");
printf("Name: %s\n", [Link]);
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 6
STRUCTURED PROGRAMMING IN C Module-VI
printf("Roll: %d\n", [Link]);
printf("Marks: ");
for(i = 0; i < 5; i++)
printf("%d ", [Link][i]);
return 0;
}
Array of structures
An array of structures in C means we create multiple structure variables
together in a single array, just like an array of int or float.
Example: Array of Structures
#include<stdio.h>
struct Student
{
int id;
char name[20];
};
int main()
{
// Declare an array of structures
struct Students[3] = { {101, "Rahul"},
{102, "Anjali"},
{103, "Kiran"}
};
// Display details
for(int i = 0; i <3; i++)
{
printf("ID: %d\n", s[i].id);
printf("Name: %s\n", s[i].name);
}
return0;
}
Union
A union is a user defined data type available in C that allows to store
multiple values with different data types in the same memory location. You
can define a union with many members, but only one member can contain
a value at any given time. Unions provide an efficient way of using the
same memory location for multiple-purpose.
syntax :-
union union_name
{
datatype member-1;
datatype member-2;
…
datatype member-n;
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 7
STRUCTURED PROGRAMMING IN C Module-VI
}union_variable;
union is a keyword and union_name is name given to union.
member-1, member-2, ………….,member-n are the members of the
union.
In case of a union, memory will be allocated to only one member which
requires highest memory. This memory can be shared by all of union
members.
The syntax for declaring a variable of union type is
union union_name var1,var2,……varn;
ex: consider the following declarations
union Student
{
int rno;
char sname[100],cname[50];
};
union Student s;
here “s” is a variable of student union. As a result, only one memory
location gets allocated and the size of the memory location is 100 bytes
which is equal to the size of the largest sized data “sname” in the
member list.
/*program to illustrate unions*/
#include<stdio.h>
union student
{
int rno;
char sname[100],cname[30];
};
void main()
{
union student s;
printf("Enter rno : ");
scanf("%d",&[Link]);
printf("Rno=%d\n",[Link]);
printf("Enter student name : ");
scanf("%s",&[Link]);
printf("Sname=%s\n",[Link]);
printf("Enter cname : ");
scanf("%s",&[Link]);
printf("Cname=%s\n",[Link]);
}
Enter rno : 501
Rno=501
Enter student name : Raja
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 8
STRUCTURED PROGRAMMING IN C Module-VI
Sname=Raja
Enter cname : CSE
Cname=CSE
Difference between Structure and Union
Feature Structure Union
A collection of variables of A collection of variables of
Definition different data types stored different data types stored in
together. the same memory location.
It always begins with It always begins with “union”
Keyword
“struct” keyword. keyword.
Each member has
All members share the same
Memory separate memory. Total
memory. Size = size of the
Allocation size = sum of sizes of all
largest member.
members (with padding).
All members can be Only one member can hold a
Access accessed independently value at a time (new value
at the same time. overwrites the old one).
All members can be Only the first member can be
Initialization
initialized at once. initialized at declaration.
Useful when we need to Useful when we need to store a
store information about an value that may be of different
Usage entity with multiple types at different times
attributes (e.g., student (e.g., variant data types,
record). memory-saving).
Struct StructureName union StructureName
{ {
Datatype member1; Datatype member1;
Syntax
Datatype member2; Datatype member2;
Datatype memberN; Datatype memberN;
}structure_variable; }union_variable;
structstudent
unionstudent
{
{
int rollno;
int rollno;
Example char sname[100];
char sname[100];
Char cname[50];
Char cname[50];
}s1;
}s1;
Typedef
In C language, typedef is a keyword used to create a new name (alias)
for an existing data type. It makes code shorter and cleaner. It avoids
repeatedly writing long type declarations. It improves portability (easy to
change data types later).It is useful with structures, pointers, function
pointers
Syntax
typedef existing_data_type new_data_type_name;
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 9
STRUCTURED PROGRAMMING IN C Module-VI
Example 1: Simple Type Alias
#include<stdio.h>
typedef int vvit; // alias for int
int main()
{
vvit a = 10, b = 20; // use alias
printf("a = %d, b = %d\n", a, b);
return 0;
}
Here,”vvit” is just another name for int.
Example 2: Using typedef with struct
Without typedef:
struct Student
{
int id;
char name[20];
};
struct Student s1; // must use "struct" keyword
With typedef:
typedef struct
{
int id;
char name[20];
} Student;
int main()
{
Student s1 = {101, "Rahul"}; // no need to write "struct"
printf("ID: %d, Name: %s\n", [Link], [Link]);
return 0;
}
Now Student acts like a new data type.
enum
In C language,enum stands for enumeration. It is a user-defined data
[Link] allows us to assign names to integral constants to making our code
more readable and maintainable.
Syntax
enum enum_name
{
constant1, constant2, constant3, …
};
enum_name is the name of the enumeration (optional, but usually
given).
constant1, constant2, ...are identifiers that represent integer values.
Example
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 10
STRUCTURED PROGRAMMING IN C Module-VI
#include<stdio.h>
enum Weekdays
{
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY,
SUNDAY
};
int main()
{
enum Weekdays today;
today = WEDNESDAY;
printf("Today is day number: %d\n", today);
return 0;
}
Output:
Today is day number: 2
File :
A file is defined to be a collection of related data. Files are stored
on secondary storage devices (like hard disk, CD or DVD).
Need of a file :
A program takes some inputs, performs some manipulations
over them and produces required outputs. Generally, the inputs are
given through the standard input device i.e., keyboard with the help
of scanf( ), getchar( ) and gets( ) functions. The outputs are produced
through the standard output devices such as monitor by the use of
printf( ), putchar( ) and puts( ) functions. This type of I/O operations
has the following drawbacks.
1. The entire data is lost when either the program is terminated or
the computer is turned off.
2. It is very difficult and time consuming to handle large volumes of
data through terminals.
It is therefore necessary to store data on the disks and read
without destroying data. For this, we need files to store and
retrieval of data.
Types of Files
Depending upon the format in which data is stored, files are
categorized into two types:
a) Text File
b) Binary File
a) Text File:
The text files are those files that contain textual information
like alphabets, digits and special symbols etc. The text files store
the ASCII encrypted information. Since data is stored in a storage
device in the binary format, the text file contents are converted in
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 11
STRUCTURED PROGRAMMING IN C Module-VI
the binary form before actually being stored in the storage
device.
Ex: C Source code files and files with .txt extension
b) Binary File:
A binary file stores the information in the binary form i.e., in the
same format as it is stored in the memory. Thus, the use of binary
file eliminates the need of data conversion from text to binary
format for storage [Link] data stored in a binary file is not
in human understandable form. All the files with .exe extension
are the examples of binary.
File Modes or Purpose
When we open a file, we explicitly define its mode. The mode
shows how we will use the file i.e., whether the file is to be read,
written or to append data at the end. Mode of opening can be any
one of the following.
File Mode Purpose
r Opens file(text) for reading only
w Opens file(text) for Writing only
a Opens file(text) for appending only
r+ Opens file(text) for reading and writing only
w+ Same as w except both for reading and writing only
a+ Same as a except both for reading and writing only
rb Opens binary file for reading only
wb Opens binary file for Writing only
ab Opens binary file for appending only
1. w :-
-----------------
it stands for write mode.
it allows to write.
it create a new file.
if file already exist then it delete and recreate the file.
2. r :-
--------------
it stands for read mode.
it allows to read.
it open an existing file.
if the file does not exist then it produce error.
3. a :-
-------------------
it stands for append mode.
it allows to append.
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 12
STRUCTURED PROGRAMMING IN C Module-VI
it open an existing file.
if the file does not exist then it create a new file.
4. w+:-
----------------
it stands for write plus mode.
it allows to write and read.
it create a new file
if file already exist then it delete and recreate the file.
5. r+ :-
--------------
it stands for read plus mode.
it allows to read and write.
it opens an existing file.
if file does not exist then it produce error.
6. a+ :-
-----------------
it stands for append plus mode.
it allows to append and read.
if opens an existing file.
if file does not exist then create a new file.
7. wb :-
---------------
it stands for write binary mode.
it allows to write into binary file.
it create a new binary file.
if the file already exist then delete and recreate the file.
8. rb :-
----------------
it stands for read binary mode.
it allows to read into binary file.
it opens an existing binary file.
if file does not exist then it produce error.
9. ab :-
---------------
it stands for append binary mode.
it allows to append into binary file.
it opens an existing binary file.
if file does not exist then it create a new binary file.
Ex: FILE *fptr;
fptr=fopen(“[Link]
”,”r”);
here fptr is pointer that contains the address of the structure FILE
that has been defined in the header file stdio.h and the function
fopen( ) opens a file [Link] in read mode
File handling functions
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 13
STRUCTURED PROGRAMMING IN C Module-VI
C supports a number of functions to perform various file
operations like
Naming of a file / creating a file
Opening a file
Reading data from a file
Writing data to a file
Appending data to a file
Closin
g a file Some of the
file handling functions
are
Function operation
name
fopen( ) Creates a new file for use (or) Opens an existing file for use
fclose( ) Closes a file which has been opened for use
fcloseall() Closes all files those are opened.
fgetc( ) Reads a character from a file
fputc( ) Writes a character to a file
fgets() Reads a string from file
fputs() Writes a string to a file.
fgetw() Reads a number from a file
fputw() Writes a number to a file
fscanf() Reads a set of data values from a file
fprintf( ) Writes a set of data values to a file
fread() Reads N bytes of data from file.
fwrite() Writes N bytes of data in file.
feof() Tests whether file pointer reached to end of file or not.
ferror() Tests whether error occurred or not.
fseek( ) Sets the position to a desired position in the file
ftell( ) Gives the current position in the file
rewind( ) Sets the position to the beginning of the file
Defining and Opening a file
If we want to store data in a file in the secondary memory, we
must specify certain things about the file, to the operating system.
They include
1. Filename
2. Data Structure
3. File Mode or Purpose
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 14
STRUCTURED PROGRAMMING IN C Module-VI
Naming of File:
Filename is a string of characters that make up a valid filename for
the operating system. When we name the files we must use the
operating systems [Link] may contain two parts, a primary name
and an optional period(.) with the extension.
Example : [Link]
Data structure of a File:
C provides a data structure called FILE, declared in stdio.h, to
hold the information about the files, to acces the stream of
characters from the disk files. Therefore, all files should be declared
as type FILE before they are used. When we open a file, we must
specify what we want to do with the file.
The general format for declaring and opening a file is
FILE *fp;
fp=fopen(“filename”, ”mode”);
Here fp is a pointer to the FILE Structure. This acts as a link
between the operating system and a program. The fopen function
returns the value which contains the file structure address. The
pointer fp is assigned the address of the file structure when we
open the file
Closing a file
After the required operations such as reading, writing or
appending operations on a file are done, the file needs to be
closed. This can be done by using fclose( ) function.
The general form is
fclose(file_pointer);
This would close the file associated with the
FILE pointer.
Ex:
FILE *p1,*p2;
P1=fopen(“[Link]”,”w”);
P2=fopen(“[Link]”,”r”);
fclose(p1);
fclose(p2);
Example Program:
/*program to illustrate opening and closing a file*/
#include<stdio.h>
void main( )
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 15
STRUCTURED PROGRAMMING IN C Module-VI
{
FILE *fp;
char ch;
fp=fopen(“[Link]”,”r”);/*opening a file*/
if(fp==NULL)
{
Printf(“source file cannot be opened\n”);
exit(0);
}
printf(“source file is successfully opened\n”);
fclose(fp); /*closing a file*/
}
File I/O functions
C standard library supports a number of functions which can be used
for performing I/O operations. These are divided into two types. They
are
a) Unformatted file I/O functions
b) Formatted file I/O functions
Unformatted file I/O functions
The unformatted input/output functions only work with the character
data type. They do not require conversion symbol for identifications
of data types because they work only with character data type.
getc( ) and putc( ) functions:
The getc function is used to read a character from a file that has been
opened in read mode.
For example, the statement
c=getc(fp1);
would read a character from the file whose file pointer is fp1. The
getc() will return an end-of-file marker EOF, when end of the file has
been reached. Therefore, reading should be terminated when EOF is
encountered.
Assume that a file is opened with mode w and file pointer [Link]
the statement
putc(c,fp2);
Writes a character contained in the character variable c to the file
whose file pointer is fp2. The file pointer moves by one character
position for every operation of getc( ) or putc( ).
Example program:
/*program to read data from the keyboard and write it to a file called
INPUT and again read the same data from the INPUT file and display it
on the screen*/
#include<stdio.h>
void main( )
{
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 16
STRUCTURED PROGRAMMING IN C Module-VI
FILE *f1;
char c;
f1=fopen(“Input”,”w”);
printf(“enter the data\n”);
while( ( c=getchar( ) ) !=EOF )
{
putc(c,f1);
}
fclose(f1);
f1=fopen(“Input”,”r”);
printf(“the data you entered is\n”);
while( !feof(fp) )
{
c=getc(f1) ;
printf(“%c”,c);
}
fclose(f1);
}
Formatted I/O file functions:
The formatted input/output functions read and write all types of data
values. They require a conversion symbol to identify the data type.
fscanf( ) and fprintf( ) functions:
The functions fprintf( ) and fscanf( ) perform I/O operations that are
identical to the printf( ) and
scanf( ) functions, except they work on files.
The general form of fscanf( ) is
fscanf(fp,”formatted specifiers”,variables_list);
where fp is a file pointer associated with a file that has been opened
for reading. This statement would cause the reading of the items in
the list from the file specified by fp according to the specifications
contained in the control string.
Ex: fscanf(f2,”%s%d”,&item,&quantity);
The general form of fprintf( ) is
fprintf(fp,” formatted specifiers”,variableslist);
where fp is a file pointer associated with a file that has been opened
for writing. Ex:
fprintf(f1,”%s %d %f”,name, age, 7.5);
Example Program :-
#include<stdio.h>
void main()
{
FILE *fp;
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 17
STRUCTURED PROGRAMMING IN C Module-VI
int rno;
char sname[100],cname[20];
fp=fopen("[Link]","w");
if( fp==NULL )
{
printf("File error");
exit(0);
}
printf("Enter rno, sname, cname : ");
scanf("%d%s%s",&rno,&sname,&cname);
fprintf(fp,"%d %s %s",rno,sname,cname);
printf("Student information saved in file.\n");
fclose(fp);
fp=fopen("[Link]","r");
if( fp==NULL )
{
printf("File error");
exit(0);
}
fscanf(fp,"%d%s%s",&rno,&sname,&cname);
printf("Data read from file : ");
printf("\nRno=%d",rno);
printf("\nSname=%s",sname);
printf("\nCname=%s",cname);
fclose(fp);
}
1. Program to copy a file into another file.
#include<stdio.h>
void main()
{
FILE *fp1, *fp2;
char ch;
fp1=fopen("[Link]","r");
fp2=fopen("[Link]","w");
while( !feof(fp1))
{
ch=fgetc( fp1 );
if( feof(fp1))
break;
fputc( ch, fp2);
}
fclose(fp1);
fclose(fp2);
printf(“File copied”);
}
output: File copied
2. Program to merge 2 files.
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 18
STRUCTURED PROGRAMMING IN C Module-VI
#include<stdio.h>
void main()
{
FILE *fp1, *fp2, *fp3;
char ch;
fp1=fopen("[Link]","r");
fp2=fopen("[Link]","r");
fp3=fopen("[Link]","w");
while( !feof( fp1 ))
{
ch=fgetc(fp1);
if( feof(fp1))
break;
fputc(ch,fp3);
}
while( !feof(fp2))
{
ch=fgetc(fp2);
if( feof(fp2))
break;
fputc(ch,fp3);
}
printf("Files merged");
fclose(fp1);
fclose(fp2);
fclose(fp3);
}
output : Files merged
VASIREDDY VENKATADRI INSTITUTE OF TECHNOLOGICAL UNIERSITY (VVITU) Page 19