Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Data structure using c - introduction(BCA)

Rating
-
Sold
-
Pages
36
Uploaded on
26-08-2025
Written in
2024/2025

This document contains comprehensive notes on Data Structures using C, designed for BCA, BSc, MCA, and Computer Science students. It covers all fundamental concepts with clear explanations, algorithms, and C programs for better understanding. Topics Covered: Introduction to Data Structures Arrays and Strings in C Stacks and Queues (with C programs) Linked Lists (Singly, Doubly, Circular) Trees and Graphs Basics Searching and Sorting Techniques File Handling in C These notes are well-structured, exam-focused, and easy to follow, making them perfect for both beginners and quick revision before exams.

Show more Read less
Institution
Course

Content preview

Data structure using-C

UNIT-1
INTRODUCTION
File Handling:

File handling in C is the process in which we create, open, read, write, and close
operations on a file. C language provides different functions such as fopen(),
fwrite(), fread(), fseek(), fprintf(), etc. to perform input, output, and many
different C file operations in our program.

Types of Files in C

A file can be classified into two types based on the way the file stores the data.
They are as follows:

1. Text Files

2. Binary Files




1. Text Files

 A text file contains data in the form of ASCII characters and is generally
used to store a stream of characters.
 Each line in a text file ends with a new line character (‘\n’).
 It can be read or written by any text editor.
 They are generally stored with .txt file extension.
 Text files can also be used to store the source code.

SHIVAKUMAR C.R , A.G.B First Grade College, Davangere 1

, Data structure using-C

2. Binary Files

 A binary file contains data in binary form (i.e. 0’s and 1’s) instead of ASCII
characters. They contain data that is stored in a similar manner to how it is
stored in the main memory.
 The binary files can be created only from within a program and their
contents can only be read by a program.
 More secure as they are not easily readable.
 They are generally stored with .bin file extension.

Opening a file

Before we perform any operations on a file, we need to open it. We do this
by using a file pointer. The type FILE defined in stdio.h allows us to define
a file pointer. Then you use the function fopen() for opening a file. Once
this is done one can read or write to the file using the fread() or fwrite()
functions, respectively. The fclose() function is used to explicitly close any
opened file.

Taking the preceding statements into account let us look at the following
example program :

fopen()
#include <stdio.h>
main ()
{
FILE *fp;
fp = fopen("data.txt", "r");
if (fp == NULL) {
printf("File does not exist,
please check!\n");
}


SHIVAKUMAR C.R , A.G.B First Grade College, Davangere 2

, Data structure using-C

fclose(fp);}
Let us first discuss fopen(). This function accepts two arguments as strings. The
first argument denotes the name of the file to be opened and the second signifies
the mode in which the file is to be opened. The second argument can be any of
the following:

File Mode Description

r Open a text file for reading

w Create a text file for writing, if it exists, it is overwritten.

a Open a text file and append text to the end of the file.

rb Open a binary file for reading

wb Create a binary file for writing, if it exists, it is overwritten.

ab Open a binary file and append data to the end of the file.



fclose()

The fclose() function is used for closing opened files. The only argument it
accepts is the file pointer.

If a program terminates, it automatically closes all opened files. But it is a good
programming habit to close any file once it is no longer needed. This helps in
better utilization of system resources, and is very useful when you are working
on numerous files simultaneously. Some operating systems place a limit on the
number of files that can be open at any given point in time.




SHIVAKUMAR C.R , A.G.B First Grade College, Davangere 3

, Data structure using-C

fscanf() and fprintf()

The functions fprintf() and fscanf() are similar to printf() and scanf() except that
these functions operate on files and require one additional and first argument to
be a file pointer.
Example:


#include <stdio.h>
main ()
{
FILE *fp;
float total;
fp = fopen("data.txt", "w+");
if (fp == NULL) {
printf("data.txt does not exist, please check!\n");
exit (1);
}
fprintf(fp, 100);
fscanf(fp, "%f", &total);
fclose(fp);
printf("Value of total is %f\n", total);
}

getc() and putc()

The functions getc() and putc() are equivalent to getchar() and putchar()
functions on Input and Output, except that these functions require an argument
which is the file pointer. Function getc() reads a single character from the file
which has previously been opened using a function like fopen(). Function putc()



SHIVAKUMAR C.R , A.G.B First Grade College, Davangere 4

Written for

Institution
Course

Document information

Uploaded on
August 26, 2025
Number of pages
36
Written in
2024/2025
Type
Class notes
Professor(s)
..
Contains
..

Subjects

$5.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
keerthanahn

Also available in package deal

Get to know the seller

Seller avatar
keerthanahn Indian institute of technology Bombay
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
8 months
Number of followers
0
Documents
11
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions