0% found this document useful (0 votes)
17 views4 pages

cs3251 UNIT V QBANK

programming in C

Uploaded by

merrysummer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

cs3251 UNIT V QBANK

programming in C

Uploaded by

merrysummer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Part – A RBT

1 Why files are needed? AP


Files allow seamless data exchange between different programs and even across different
computers.
storing data in a file, you ensure its persistence beyond the program’s lifetime.
can easily access it using a few elegant commands
2 Types of Files? AP

Application Files:

These files contain executable code (programs) that perform specific tasks.

Examples: .exe (Windows executables), .app (macOS applications), .apk (Android apps).

Data Files:

Data files store information created or used by applications.

Examples:

Text Files: Contain plain text (e.g., .txt, .csv, .log).

Spreadsheet Files: Organize data in rows and columns (e.g., .xlsx, .ods).

Database Files: Store structured data (e.g., .sqlite, .mdb).

XML Files: Represent data in a hierarchical format (e.g., .xml).

System Files:

These files are essential for the operating system and system utilities.

Examples:

Configuration Files: Set system parameters (e.g., .ini, .conf).

Library Files: Contain reusable code (e.g., .dll, .so).

Driver Files: Enable communication with hardware (e.g., .sys, .kext).

Media Files:

These files store multimedia content.

Examples:

Image Files:

JPEG/JPG: Common for photos (lossy compression).

GIF: Supports short animations.

SVG: Scalable vector graphics (great for logos).

Audio Files:

MP3: Compressed audio.

FLAC: Lossless audio.

WAV: Uncompressed audio.

Video Files:

AVI: Video container.

MP4: Widely used for videos.

Document Files:

PDF: Portable Document Format.

DOCX: Microsoft Word documents.

PPTX: PowerPoint presentations.

Compressed Files:
These files bundle other files together for efficient storage or transfer.

Examples:

ZIP: General-purpose compression.

RAR: Similar to ZIP but with additional features.

7z: High compression ratio.

Executable Files:

These files contain machine code and can be run directly by the computer.

Examples: .exe, .sh, .bat

3 Enlist the File Operations AP

Creating a New File:

Use fopen() with attributes like "a" (append), "a+" (append and read), "w" (write), or "w+" (write
and read).

This function creates a new file or opens an existing one for writing or appending data.

Opening an Existing File:

Again, fopen() is your trusty companion.

You can open an existing file for reading or writing, depending on your needs.

Reading Data from an Existing File:

Two main options here:

fscanf(): Reads formatted data (similar to scanf() but from a file).

fgets(): Reads a line of text from the file.

Writing Data to a File:

Express your thoughts in the file using:

fprintf(): Write formatted data (like printf() but to a file).

fputs(): Write a string to the file.

Moving Data to a Specific Location in the File:

Fancy footwork with:

fseek(): Move the file pointer to a specific position.

rewind(): Elegant twirl—reset the file pointer to the beginning.

Closing the File:

Polite closure with fclose().

4 How to open a file? AP

The fopen() Function:

To open a file, we use the fopen() function, which comes from the stdio.h header.

The syntax for opening a file is:

FILE *ptr;

ptr = fopen("file_name", "access_mode");

Access Modes:

When you send out your invitations (i.e., open a file), choose the perfect mode:

"r": Open for reading. If the file doesn’t exist, fopen() returns NULL.

"rb": Open for reading in binary mode (useful for non-text files).

"w": Open for writing. If the file exists, its contents are overwritten. If not, a new file is created.
"wb": Open for writing in binary mode.

And more! (Check the documentation for additional modes.)

5 List the opening modes in standard I/O? AP

Read Mode ("r"):

Open the file for reading.

If the file doesn’t exist, fopen() returns NULL.

Example: fopen("my_file.txt", "r");

Read Mode in Binary ("rb"):

Open for reading in binary mode (useful for non-text files).

Example: fopen("data.bin", "rb");

Write Mode ("w"):

Open for writing.

If the file exists, its contents are overwritten. If not, a new file is created.

Example: fopen("output.txt", "w");

Write Mode in Binary ("wb"):

Open for writing in binary mode.

Example: fopen("data.bin", "wb");

Append Mode ("a"):

Open for appending (adding data at the end).

If the file doesn’t exist, a new one is created.

Example: fopen("log.txt", "a");

Append Mode in Binary ("ab"):

Open for appending in binary mode.

Example: fopen("data.bin", "ab");

6 How to close a file? AP

The fclose() Function:

the fclose() function gracefully closes the file.

The syntax

fclose(file_pointer);

Here, file_pointer is the pointer associated with the file you want to close.

7 What are two main ways a file can be organized? AP

the two main ways files can be organized:

Sequential Access:

When accessing data, you process it sequentially—one after another. To reach a specific item of
data, you must read all the data that precedes it.

Random Access:

directly access any item of data without reading everything that comes before it.

8 What is file? AP

A file is a collection of data or information, neatly bundled together and given a name—the
filename

files are organized into records The data inside the file is somehow organized. We call this
organization a file format.

9 A file ‘books.dat’ contains the data of various author books, write a code to access the file and AP
read its contents to display on console.

10 In file manipulation process define a code for the following operations AP

a) To set the position indicator in new position where the location is known
b) To save the current position of the indicator for future relocation of indicator.

11 State Report Generation? AP

State report generation involves creating structured and meaningful reports based on collected
data to provide insights and information for decision-making.

12 State Transaction Processing? AP

a transaction represents a logical unit of work that consists of one or more database operations
(such as reads, writes, or updates).

Part – B RBT

1 What is command line arguments? Write an example program for command line arguments AP

2 Write short notes on fseek()? Give an example for fseek() AP

3 Explain about files and with it types of file processing AP

4 Write a C program to read name and marks of n number of students from user and store them in a AP
file?

5 Write a C program to write all the members of an array of structures to a file using fwrite(). Read AP
the array from the file and display on the screen

6 Explain about the random access? And gibe the properties of file operating AP

7 Determine the Compare sequential access and random access? AP

8 Write short notes on ferror(). ferror()? Write short notes on fscanf ().Write short notes on fprintf ().? AP

9 A file is created to store employee records with name, address, contact no, employee id, basic AP
salary, allowance and deduction. Write a C program to count number of records, display current
position of record, and moving position to the particular employee record.

10 A student record is stored as ‘student.dat’ with name and marks of ‘n’ number of students. Write a AP
C program to read and access them in a file to get the details of particular student or student with
particular marks, number of students with marks above or below average.

You might also like