SlideShare a Scribd company logo
1 of 107
Unit-5.2
Pointer, Structure, Union
&
Intro to File Handling
Course: BTECH
Subject: Programming In C Language
What is a File?
ā€¢ A file is a collection on information, usually
stored on a computerā€™s disk. Information can
be saved to files and then later reused.
File Names
ā€¢ All files are assigned a name that is used for
identification purposes by the operating
system and the user.
Table
File Name and Extension File Contents
MYPROG.BAS BASIC program
MENU.BAT DOS Batch File
INSTALL.DOC Documentation File
CRUNCH.EXE Executable File
BOB.HTML HTML (Hypertext Markup Language) File
3DMODEL.JAVA Java program or applet
INVENT.OBJ Object File
PROG1.PRJ Borland C++ Project File
ANSI.SYS System Device Driver
README.TXT Text File
Focus on Software Engineering: The
Process of Using a File
ā€¢ Using a file in a program is a simple three-step
process
ā€“ The file must be opened. If the file does not yet
exits, opening it means creating it.
ā€“ Information is then saved to the file, read from
the file, or both.
ā€“ When the program is finished using the file, the
file must be closed.
Figure
Figure
Setting Up a Program for File
Input/Output
ā€¢ Before file I/O can be performed, a C++
program must be set up properly.
ā€¢ File access requires the inclusion of fstream.h
Opening a File
ā€¢ Before data can be written to or read from a
file, the file must be opened.
ifstream inputFile;
inputFile.open(ā€œcustomer.datā€);
Program
// This program demonstrates the declaration of an fstream
// object and the opening of a file.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile; // Declare file stream object
char fileName[81];
cout << "Enter the name of a file you wish to openn";
cout << "or create: ";
cin.getline(fileName, 81);
dataFile.open(fileName, ios::out);
cout << "The file " << fileName << " was opened.n";
}
Program Output with Example Input
Enter the name of a file you wish to open
or create: mystuff.dat [Enter]
The file mystuff.dat was opened.
Table 3
File Type Default Open Mode
ofstream The file is opened for output only. (Information may be
written to the file, but not read from the file.) If the file
does not exist, it is created. If the file already exists, its
contents are deleted (the file is truncated).
ifstream The file is opened for input only. (Information may be
read from the file, but not written to it.) The fileā€™s
contents will be read from its beginning. If the file does
not exist, the open function fails.
Table 4
File Mode Flag Meaning
ios::app Append mode. If the file already exists, its
contents are preserved and all output is
written to the end of the file. By default, this
flag causes the file to be created if it does
not exist.
ios::ate If the file already exists, the program goes
directly to the end of it. Output may be
written anywhere in the file.
ios::binary Binary mode. When a file is opened in
binary mode, information is written to or
read from it in pure binary format. (The
default mode is text.)
ios::in Input mode. Information will be read from
the file. If the file does not exist, it will not
be created and the open function will fail.
Table 4 continued
File Mode
Flag
Meaning
ios::nocreate If the file does not already exist, this flag
will cause the open function to fail. (The file
will not be created.)
ios::noreplace If the file already exists, this flag will cause
the open function to fail. (The existing file
will not be opened.)
ios::out Output mode. Information will be written to
the file. By default, the fileā€™s contents will
be deleted if it already exists.
ios::trunc If the file already exists, its contents will be
deleted (truncated). This is the default
mode used by ios::out.
Opening a File at Declaration
fstream dataFile(ā€œnames.datā€, ios::in | ios::out);
Program 2
// This program demonstrates the opening of a file at the
// time the file stream object is declared.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile("names.dat", ios::in | ios::out);
cout << "The file names.dat was opened.n";
}
Program Output with Example Input
The file names.dat was opened.
Testing for Open Errors
dataFile.open(ā€œcust.datā€, ios::in);
if (!dataFile)
{
cout << ā€œError opening file.nā€;
}
Another way to Test for Open Errors
dataFile.open(ā€œcust.datā€, ios::in);
if (dataFile.fail())
{
cout << ā€œError opening file.nā€;
}
Closing a File
ā€¢ A file should be closed when a program is
finished using it.
Program 3
// This program demonstrates the close function.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile;
dataFile.open("testfile.txt", ios::out);
if (!dataFile)
{
cout << "File open error!" << endl;
return;
}
cout << "File was created successfully.n";
cout << "Now closing the file.n";
dataFile.close();
}
Program Output
File was created successfully.
Now closing the file.
7 Using << to Write Information to a
File
ā€¢ The stream insertion operator (<<) may be
used to write information to a file.
outputFile << ā€œI love C++ programming !ā€
Program 4
// This program uses the << operator to write information to a file.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile;
char line[81];
dataFile.open("demofile.txt", ios::out);
if (!dataFile)
{
cout << "File open error!" << endl;
return;
}
Program continues
cout << "File opened successfully.n";
cout << "Now writing information to the file.n";
dataFile << "Jonesn";
dataFile << "Smithn";
dataFile << "Willisn";
dataFile << "Davisn";
dataFile.close();
cout << "Done.n";
}
Program Screen Output
File opened successfully.
Now writing information to the file.
Done.
Output to File demofile.txt
Jones
Smith
Willis
Davis
Figure 3
Program 5
// This program writes information to a file, closes the file,
// then reopens it and appends more information.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile;
dataFile.open("demofile.txt", ios::out);
dataFile << "Jonesn";
dataFile << "Smithn";
dataFile.close();
dataFile.open("demofile.txt", ios::app);
dataFile << "Willisn";
dataFile << "Davisn";
dataFile.close();
}
Output to File demofile.txt
Jones
Smith
Willis
Davis
8 File Output Formatting
ā€¢ File output may be formatted the same way as
screen output.
Program 6
// This program uses the precision member function of a
// file stream object to format file output.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile;
float num = 123.456;
dataFile.open("numfile.txt", ios::out);
if (!dataFile)
{
cout << "File open error!" << endl;
return;
}
Program continues
dataFile << num << endl;
dataFile.precision(5);
dataFile << num << endl;
dataFile.precision(4);
dataFile << num << endl;
dataFile.precision(3);
dataFile << num << endl;
}
Contents of File numfile.txt
123.456
123.46
123.5
124
Program 7
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
void main(void)
{ fstream outFile("table.txt", ios::out);
int nums[3][3] = { 2897, 5, 837,
34, 7, 1623,
390, 3456, 12 };
// Write the three rows of numbers
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
outFile << setw(4) << nums[row][col] << " ";
}
outFile << endl;
}
outFile.close();
}
Contents of File TABLE.TXT
2897 5 837
34 7 1623
390 3456 12
Figure 6
9 Using >> to Read Information from a
File
ā€¢ The stream extraction operator (>>) may be
used to read information from a file.
Program 8
// This program uses the >> operator to read information from a file.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile;
char name[81];
dataFile.open("demofile.txt", ios::in);
if (!dataFile)
{
cout << "File open error!" << endl;
return;
}
cout << "File opened successfully.n";
cout << "Now reading information from the file.nn";
Program continues
for (int count = 0; count < 4; count++)
{
dataFile >> name;
cout << name << endl;
}
dataFile.close();
cout << "nDone.n";
}
Program Screen Output
File opened successfully.
Now reading information from the file.
Jones
Smith
Willis
Davis
Done.
10 Detecting the End of a File
ā€¢ The eof() member function reports when
the end of a file has been encountered.
if (inFile.eof())
inFile.close();
Program 9
// This program uses the file stream object's eof() member
// function to detect the end of the file.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile;
char name[81];
dataFile.open("demofile.txt", ios::in);
if (!dataFile)
{
cout << "File open error!" << endl;
return;
}
cout << "File opened successfully.n";
cout << "Now reading information from the file.nn";
Program continues
dataFile >> name; // Read first name from the file
while (!dataFile.eof())
{
cout << name << endl;
dataFile >> name;
}
dataFile.close();
cout << "nDone.n";
}
Program Screen Output
File opened successfully.
Now reading information from the file.
Jones
Smith
Willis
Davis
Done.
Note on eof()
ā€¢ In C++, ā€œend of fileā€ doesnā€™t mean the
program is at the last piece of information in
the file, but beyond it. The eof() function
returns true when there is no more
information to be read.
11 Passing File Stream Objects to
Functions
ā€¢ File stream objects may be passed by reference to
functions.
bool openFileIn(fstream &file, char name[51])
{
bool status;
file.open(name, ios::in);
if (file.fail())
status = false;
else
status = true;
return status;
}
12.12 More Detailed Error Testing
ā€¢ All stream objects have error state bits that
indicate the condition of the stream.
Table 5
Bit Description
ios::eofbit Set when the end of an input stream is
encountered.
ios::failbit Set when an attempted operation has failed.
ios::hardfail Set when an unrecoverable error has occurred.
ios::badbit Set when an invalid operation has been
attempted.
ios::goodbit Set when all the flags above are not set.
Indicates the stream is in good condition.
Table 6
Function Description
eof() Returns true (non-zero) if the eofbit flag is set,
otherwise returns false.
fail() Returns true (non-zero) if the failbit or hardfail
flags are set, otherwise returns false.
bad() Returns true (non-zero) if the badbit flag is set,
otherwise returns false.
good() Returns true (non-zero) if the goodbit flag is
set, otherwise returns false.
clear() When called with no arguments, clears all the
flags listed above. Can also be called with a
specific flag as an argument.
Program 11
// This program demonstrates the return value of the stream
// object error testing member functions.
#include <iostream.h>
#include <fstream.h>
// Function prototype
void showState(fstream &);
void main(void)
{
fstream testFile("stuff.dat", ios::out);
if (testFile.fail())
{
cout << "cannot open the file.n";
return;
}
Program continues
int num = 10;
cout << "Writing to the file.n";
testFile << num; // Write the integer to testFile
showState(testFile);
testFile.close(); // Close the file
testFile.open("stuff.dat", ios::in); // Open for input
if (testFile.fail())
{
cout << "cannot open the file.n";
return;
}
Program continues
cout << "Reading from the file.n";
testFile >> num; // Read the only number in the file
showState(testFile);
cout << "Forcing a bad read operation.n";
testFile >> num; // Force an invalid read operation
showState(testFile);
testFile.close(); // Close the file
}
// Definition of function ShowState. This function uses
// an fstream reference as its parameter. The return values of
// the eof(), fail(), bad(), and good() member functions are
// displayed. The clear() function is called before the function
// returns.
Program continues
void showState(fstream &file)
{
cout << "File Status:n";
cout << " eof bit: " << file.eof() << endl;
cout << " fail bit: " << file.fail() << endl;
cout << " bad bit: " << file.bad() << endl;
cout << " good bit: " << file.good() << endl;
file.clear(); // Clear any bad bits
}
Program Output
Writing to the file.
File Status:
eof bit: 0
fail bit: 0
bad bit: 0
good bit: 1
Reading from the file.
File Status:
eof bit: 0
fail bit: 0
bad bit: 0
good bit: 1
Forcing a bad read operation.
File Status:
eof bit: 1
fail bit: 2
bad bit: 0
good bit: 0
13 Member Functions for Reading and
Writing Files
ā€¢ File stream objects have member functions for
more specialized file reading and writing.
Figure -8
Program -12
// This program uses the file stream object's eof() member
// function to detect the end of the file.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream nameFile;
char input[81];
nameFile.open("murphy.txt", ios::in);
if (!nameFile)
{
cout << "File open error!" << endl;
return;
}
Program -12 (continued)
nameFile >> input;
while (!nameFile.eof())
{
cout << input;
nameFile >> input;
}
nameFile.close();
}
Program Screen Output
JayneMurphy47JonesCircleAlmond,NC28702
The getline Member Function
ā€¢ dataFile.getline(str, 81, ā€˜nā€™);
str ā€“ This is the name of a character array, or a pointer to a section of
memory. The information read from the file will be stored here.
81 ā€“ This number is one greater than the maximum number of
characters to be read. In this example, a maximum of 80
characters will be read.
ā€˜nā€™ ā€“ This is a delimiter character of your choice. If this delimiter is
encountered, it will cause the function to stop reading before it
has read the maximum number of characters. (This argument is
optional. If itā€™s left our, ā€˜nā€™ is the default.)
Program -13
// This program uses the file stream object's getline member
// function to read a line of information from the file.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream nameFile;
char input[81];
nameFile.open("murphy.txt", ios::in);
if (!nameFile)
{
cout << "File open error!" << endl;
return;
}
Program continues
nameFile.getline(input, 81); // use n as a delimiter
while (!nameFile.eof())
{
cout << input << endl;
nameFile.getline(input, 81); // use n as a delimiter
}
nameFile.close();
}
Program Screen Output
Jayne Murphy
47 Jones Circle
Almond, NC 28702
Program -14
// This file shows the getline function with a user-
// specified delimiter.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream dataFile("names2.txt", ios::in);
char input[81];
dataFile.getline(input, 81, '$');
while (!dataFile.eof())
{
cout << input << endl;
dataFile.getline(input, 81, '$');
}
dataFile.close();
}
Program Output
Jayne Murphy
47 Jones Circle
Almond, NC 28702
Bobbie Smith
217 Halifax Drive
Canton, NC 28716
Bill Hammet
PO Box 121
Springfield, NC 28357
The get Member Function
inFile.get(ch);
Program -15
// This program asks the user for a file name. The file is
// opened and its contents are displayed on the screen.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream file;
char ch, fileName[51];
cout << "Enter a file name: ";
cin >> fileName;
file.open(fileName, ios::in);
if (!file)
{
cout << fileName << ā€œ could not be opened.n";
return;
}
Program continues
file.get(ch); // Get a character
while (!file.eof())
{
cout << ch;
file.get(ch); // Get another character
}
file.close();
}
The put Member Function
ā€¢ outFile.put(ch);
Program -16
// This program demonstrates the put member function.
#include <iostream.h>
#include <fstream.h>
void main(void)
{ fstream dataFile("sentence.txt", ios::out);
char ch;
cout << "Type a sentence and be sure to end it with a ";
cout << "period.n";
while (1)
{
cin.get(ch);
dataFile.put(ch);
if (ch == '.')
break;
}
dataFile.close();
}
Program Screen Output with Example Input
Type a sentence and be sure to end it with a
period.
I am on my way to becoming a great programmer. [Enter]
Resulting Contents of the File SENTENCE.TXT:
I am on my way to becoming a great programmer.
14 Focus on Software Engineering:
Working with Multiple Files
ā€¢ Itā€™s possible to have more than one file open
at once in a program.
Program -17
// This program demonstrates reading from one file and writing
// to a second file.
#include <iostream.h>
#include <fstream.h>
#include <ctype.h> // Needed for the toupper function
void main(void)
{
ifstream inFile;
ofstream outFile("out.txt");
char fileName[81], ch, ch2;
cout << "Enter a file name: ";
cin >> fileName;
inFile.open(fileName);
if (!inFile)
{
cout << "Cannot open " << fileName << endl;
return;
}
Program continues
inFile.get(ch); // Get a characer from file 1
while (!inFile.eof()) // Test for end of file
{
ch2 = toupper(ch); // Convert to uppercase
outFile.put(ch2); // Write to file2
inFile.get(ch); // Get another character from file 1
}
inFile.close();
outFile.close();
cout << "File conversion done.n";
}
Program Screen Output with Example Input
Enter a file name: hownow.txt [Enter]
File conversion done.
Contents of hownow.txt:
how now brown cow.
How Now?
Resulting Contents of out.txt:
HOW NOW BROWN COW.
HOW NOW?
15 Binary Files
ā€¢ Binary files contain data that is unformatted,
and not necessarily stored as ASCII text.
file.open(ā€œstuff.datā€, ios::out | ios::binary);
Figure -9
Figure -10
Program -18
// This program uses the write and read functions.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream file(ā€œNUMS.DAT", ios::out | ios::binary);
int buffer[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
cout << "Now writing the data to the file.n";
file.write((char*)buffer, sizeof(buffer));
file.close();
file.open("NUMS.DAT", ios::in); // Reopen the file.
cout << "Now reading the data back into memory.n";
file.read((char*)buffer, sizeof(buffer));
for (int count = 0; count < 10; count++)
cout << buffer[count] << " ";
file.close();
}
Program Screen Output
Now writing the data to the file.
Now reading the data back into memory.
1 2 3 4 5 6 7 8 9 10
16 Creating Records with Structures
ā€¢ Structures may be used to store fixed-length
records to a file.
struct Info
{
char name[51];
int age;
char address1[51];
char address2[51];
char phone[14];
};
ā€¢ Since structures can contain a mixture of data
types, you should always use the ios::binary mode
when opening a file to store them.
Program -19
// This program demonstrates the use of a structure variable to
// store a record of information to a file.
#include <iostream.h>
#include <fstream.h>
#include <ctype.h> // for toupper
// Declare a structure for the record.
struct Info
{
char name[51];
int age;
char address1[51];
char address2[51];
char phone[14];
};
Program continues
void main(void)
{
fstream people("people.dat", ios::out | ios::binary);
Info person;
char again;
if (!people)
{
cout << "Error opening file. Program aborting.n";
return;
}
do
{
cout << "Enter the following information about a ā€
<< "person:n";
cout << "Name: ";
Program continues
cin.getline(person.name, 51);
cout << "Age: ";
cin >> person.age;
cin.ignore(); // skip over remaining newline.
cout << "Address line 1: ";
cin.getline(person.address1, 51);
cout << "Address line 2: ";
cin.getline(person.address2, 51);
cout << "Phone: ";
cin.getline(person.phone, 14);
people.write((char *)&person, sizeof(person));
cout << "Do you want to enter another record? ";
cin >> again;
cin.ignore();
} while (toupper(again) == 'Y');
people.close();
}
Program Screen Output with Example Input
Enter the following information about a person:
Name: Charlie Baxter [Enter]
Age: 42 [Enter]
Address line 1: 67 Kennedy Bvd. [Enter]
Address line 2: Perth, SC 38754 [Enter]
Phone: (803)555-1234 [Enter]
Do you want to enter another record? Y [Enter]
Enter the following information about a person:
Name: Merideth Murney [Enter]
Age: 22 [Enter]
Address line 1: 487 Lindsay Lane [Enter]
Address line 2: Hazelwood, NC 28737 [Enter]
Phone: (704)453-9999 [Enter]
Do you want to enter another record? N [Enter]
17 Random Access Files
ā€¢ Random Access means non-sequentially
accessing informaiton in a file.
Figure 12-11
Table -7
Mode Flag Description
ios::beg The offset is calculated from
the beginning of the file.
ios::end The offset is calculated from
the end of the file.
ios::cur The offset is calculated from
the current position.
Table -8
Statement How it Affects the Read/Write Position
File.seekp(32L, ios::beg); Sets the write position to the 33rd byte
(byte 32) from the beginning of the file.
file.seekp(-10L, ios::end); Sets the write position to the 11th byte
(byte 10) from the end of the file.
file.seekp(120L, ios::cur); Sets the write position to the 121st byte
(byte 120) from the current position.
file.seekg(2L, ios::beg); Sets the read position to the 3rd byte
(byte 2) from the beginning of the file.
file.seekg(-100L, ios::end); Sets the read position to the 101st byte
(byte 100) from the end of the file.
file.seekg(40L, ios::cur); Sets the read position to the 41st byte
(byte 40) from the current position.
file.seekg(0L, ios::end); Sets the read position to the end of the
file.
Program -21
// This program demonstrates the seekg function.
#include <iostream.h>
#include <fstream.h>
void main(void)
{
fstream file("letters.txt", ios::in);
char ch;
file.seekg(5L, ios::beg);
file.get(ch);
cout << "Byte 5 from beginning: " << ch << endl;
file.seekg(-10L, ios::end);
file.get(ch);
cout << "Byte 10 from end: " << ch << endl;
Program continues
file.seekg(3L, ios::cur);
file.get(ch);
cout << "Byte 3 from current: " << ch << endl;
file.close();
}
Program Screen Output
Byte 5 from beginning: f
Byte 10 from end: q
Byte 3 from current: u
The tellp and tellg Member
Functions
ā€¢ tellp returns a long integer that is the
current byte number of the fileā€™s write
position.
ā€¢ tellg returns a long integer that is the
current byte number of the fileā€™s read
position.
Program -23
// This program demonstrates the tellg function.
#include <iostream.h>
#include <fstream.h>
#include <ctype.h> // For toupper
void main(void)
{
fstream file("letters.txt", ios::in);
long offset;
char ch, again;
do
{
cout << "Currently at position " << file.tellg() << endl;
cout << "Enter an offset from the beginning of the file: ";
cin >> offset;
Program continues
file.seekg(offset, ios::beg);
file.get(ch);
cout << "Character read: " << ch << endl;
cout << "Do it again? ";
cin >> again;
} while (toupper(again) == 'Y');
file.close();
}
Program Output with Example Input
Currently at position 0
Enter an offset from the beginning of the file: 5
[Enter]
Character read: f
Do it again? y [Enter]
Currently at position 6
Enter an offset from the beginning of the file: 0
[Enter]
Character read: a
Do it again? y [Enter]
Currently at position 1
Enter an offset from the beginning of the file: 20
[Enter]
Character read: u
Do it again? n [Enter]
18 Opening a File for Both Input and
Output
ā€¢ You may perform input and output on an fstream
file without closing it and reopening it.
fstream file(ā€œdata.datā€, ios::in | ios::out);
Program 24
// This program sets up a file of blank inventory records.
#include <iostream.h>
#include <fstream.h>
// Declaration of Invtry structure
struct Invtry
{
char desc[31];
int qty;
float price;
};
void main(void)
{
fstream inventory("invtry.dat", ios::out | ios::binary);
Invtry record = { "", 0, 0.0 };
Program continues
// Now write the blank records
for (int count = 0; count < 5; count++)
{
cout << "Now writing record " << count << endl;
inventory.write((char *)&record, sizeof(record));
}
inventory.close();
}
Program Screen Output
Now writing record 0
Now writing record 1
Now writing record 2
Now writing record 3
Now writing record 4
Program -25
// This program displays the contents of the inventory file.
#include <iostream.h>
#include <fstream.h>
// Declaration of Invtry structure
struct Invtry
{
char desc[31];
int qty;
float price;
};
void main(void)
{
fstream inventory("invtry.dat", ios::in | ios::binary);
Invtry record = { "", 0, 0.0 };
Program continues
// Now read and display the records
inventory.read((char *)&record, sizeof(record));
while (!inventory.eof())
{
cout << "Description: ";
cout << record.desc << endl;
cout << "Quantity: ";
cout << record.qty << endl;
cout << "Price: ";
cout << record.price << endl << endl;
inventory.read((char *)&record, sizeof(record));
}
inventory.close();
}
Here is the screen output of Program 12-25 if it is run immediately
after Program 12-24 sets up the file of blank records.
Program Screen Output
Description:
Quantity: 0
Price: 0.0
Description:
Quantity: 0
Price: 0.0
Description:
Quantity: 0
Price: 0.0
Description:
Quantity: 0
Price: 0.0
Description:
Quantity: 0
Price: 0.0
Program -26
// This program allows the user to edit a specific record in
// the inventory file.
#include <iostream.h>
#include <fstream.h>
// Declaration of Invtry structure
struct Invtry
{
char desc[31];
int qty;
float price;
};
void main(void)
{
Program continues
fstream inventory("invtry.dat", ios::in | ios::out | ios::binary);
Invtry record;
long recNum;
cout << "Which record do you want to edit?";
cin >> recNum;
inventory.seekg(recNum * sizeof(record), ios::beg);
inventory.read((char *)&record, sizeof(record));
cout << "Description: ";
cout << record.desc << endl;
cout << "Quantity: ";
cout << record.qty << endl;
cout << "Price: ";
cout << record.price << endl;
cout << "Enter the new data:n";
cout << "Description: ";
Program continues
cin.ignore();
cin.getline(record.desc, 31);
cout << "Quantity: ";
cin >> record.qty;
cout << "Price: ";
cin >> record.price;
inventory.seekp(recNum * sizeof(record), ios::beg);
inventory.write((char *)&record, sizeof(record));
inventory.close();
}
Program Screen Output with Example Input
Which record do you ant to edit? 2 [Enter]
Description:
Quantity: 0
Price: 0.0
Enter the new data:
Description: Wrench [Enter]
Quantity: 10 [Enter]
Price: 4.67 [Enter]
References
1. www.tutorialspoint.com/cprogramming/c_pointers.htm
2. www.cprogramming.com/tutorial/c/lesson6.html
3. pw1.netcom.com/~tjensen/ptr/pointers.html
4. Programming in C by yashwant kanitkar
5.ANSI C by E.balagurusamy- TMG publication
6.Computer programming and Utilization by sanjay shah Mahajan Publication
7.www.cprogramming.com/books.html
8.en.wikipedia.org/wiki/C_(programming_language)

More Related Content

What's hot

File handling in C
File handling in CFile handling in C
File handling in CKamal Acharya
Ā 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CMahendra Yadav
Ā 
Files in php
Files in phpFiles in php
Files in phpsana mateen
Ā 
File handling in C++
File handling in C++File handling in C++
File handling in C++Hitesh Kumar
Ā 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5Vikram Nandini
Ā 
File handling in c
File handling in cFile handling in c
File handling in caakanksha s
Ā 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming languagethirumalaikumar3
Ā 
Php files
Php filesPhp files
Php fileskalyani66
Ā 
File in C Programming
File in C ProgrammingFile in C Programming
File in C ProgrammingSonya Akter Rupa
Ā 
Files in C
Files in CFiles in C
Files in CPrabu U
Ā 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by FaixanŁ–FaiXy :)
Ā 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in CTushar B Kute
Ā 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsingFelix Z. Hoffmann
Ā 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'Gaurav Garg
Ā 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHPRasan Samarasinghe
Ā 

What's hot (20)

File handling in C
File handling in CFile handling in C
File handling in C
Ā 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
Ā 
Files in php
Files in phpFiles in php
Files in php
Ā 
File handling in c
File handling in cFile handling in c
File handling in c
Ā 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Ā 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
Ā 
File in c
File in cFile in c
File in c
Ā 
File handling in c
File handling in cFile handling in c
File handling in c
Ā 
File handling in c
File  handling in cFile  handling in c
File handling in c
Ā 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming language
Ā 
Php files
Php filesPhp files
Php files
Ā 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
Ā 
PHP file handling
PHP file handling PHP file handling
PHP file handling
Ā 
Files in C
Files in CFiles in C
Files in C
Ā 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
Ā 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
Ā 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
Ā 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
Ā 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHP
Ā 
file
filefile
file
Ā 

Similar to pointer, structure ,union and intro to file handling

ExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfaquacare2008
Ā 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxAssadLeo1
Ā 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5YOGESH SINGH
Ā 
Data file operations in C++ Base
Data file operations in C++ BaseData file operations in C++ Base
Data file operations in C++ BasearJun_M
Ā 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingChereLemma2
Ā 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
Ā 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
Ā 
Unit iv
Unit ivUnit iv
Unit ivdonny101
Ā 
csc1201_lecture13.ppt
csc1201_lecture13.pptcsc1201_lecture13.ppt
csc1201_lecture13.pptHEMAHEMS5
Ā 
Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptxMehul Desai
Ā 
FILES IN C
FILES IN CFILES IN C
FILES IN Cyndaravind
Ā 

Similar to pointer, structure ,union and intro to file handling (20)

File Handling
File HandlingFile Handling
File Handling
Ā 
File Handling
File HandlingFile Handling
File Handling
Ā 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
Ā 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
Ā 
File operations
File operationsFile operations
File operations
Ā 
ExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdf
Ā 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
Ā 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
Ā 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
Ā 
Data file operations in C++ Base
Data file operations in C++ BaseData file operations in C++ Base
Data file operations in C++ Base
Ā 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
Ā 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
Ā 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
Ā 
Unit iv
Unit ivUnit iv
Unit iv
Ā 
csc1201_lecture13.ppt
csc1201_lecture13.pptcsc1201_lecture13.ppt
csc1201_lecture13.ppt
Ā 
File handling
File handlingFile handling
File handling
Ā 
Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
Ā 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
Ā 
FILES IN C
FILES IN CFILES IN C
FILES IN C
Ā 
data file handling
data file handlingdata file handling
data file handling
Ā 

More from Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
Ā 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1Rai University
Ā 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
Ā 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
Ā 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
Ā 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
Ā 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
Ā 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
Ā 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
Ā 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
Ā 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
Ā 

More from Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
Ā 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
Ā 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
Ā 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
Ā 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
Ā 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
Ā 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
Ā 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
Ā 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
Ā 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
Ā 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
Ā 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Ā 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Ā 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
Ā 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
Ā 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
Ā 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
Ā 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
Ā 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
Ā 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
Ā 

Recently uploaded

Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
Ā 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
Ā 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
Ā 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
Ā 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
Ā 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
Ā 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
Ā 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
Ā 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
Ā 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
Ā 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
Ā 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
Ā 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
Ā 
Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)
Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)
Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)lakshayb543
Ā 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
Ā 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
Ā 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
Ā 

Recently uploaded (20)

Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
Ā 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
Ā 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Ā 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
Ā 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
Ā 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
Ā 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
Ā 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
Ā 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
Ā 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
Ā 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Ā 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Ā 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Ā 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
Ā 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
Ā 
Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)
Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)
Visit to a blind student's schoolšŸ§‘ā€šŸ¦ÆšŸ§‘ā€šŸ¦Æ(community medicine)
Ā 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
Ā 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
Ā 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
Ā 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
Ā 

pointer, structure ,union and intro to file handling

  • 1. Unit-5.2 Pointer, Structure, Union & Intro to File Handling Course: BTECH Subject: Programming In C Language
  • 2. What is a File? ā€¢ A file is a collection on information, usually stored on a computerā€™s disk. Information can be saved to files and then later reused.
  • 3. File Names ā€¢ All files are assigned a name that is used for identification purposes by the operating system and the user.
  • 4. Table File Name and Extension File Contents MYPROG.BAS BASIC program MENU.BAT DOS Batch File INSTALL.DOC Documentation File CRUNCH.EXE Executable File BOB.HTML HTML (Hypertext Markup Language) File 3DMODEL.JAVA Java program or applet INVENT.OBJ Object File PROG1.PRJ Borland C++ Project File ANSI.SYS System Device Driver README.TXT Text File
  • 5. Focus on Software Engineering: The Process of Using a File ā€¢ Using a file in a program is a simple three-step process ā€“ The file must be opened. If the file does not yet exits, opening it means creating it. ā€“ Information is then saved to the file, read from the file, or both. ā€“ When the program is finished using the file, the file must be closed.
  • 8. Setting Up a Program for File Input/Output ā€¢ Before file I/O can be performed, a C++ program must be set up properly. ā€¢ File access requires the inclusion of fstream.h
  • 9. Opening a File ā€¢ Before data can be written to or read from a file, the file must be opened. ifstream inputFile; inputFile.open(ā€œcustomer.datā€);
  • 10. Program // This program demonstrates the declaration of an fstream // object and the opening of a file. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; // Declare file stream object char fileName[81]; cout << "Enter the name of a file you wish to openn"; cout << "or create: "; cin.getline(fileName, 81); dataFile.open(fileName, ios::out); cout << "The file " << fileName << " was opened.n"; }
  • 11. Program Output with Example Input Enter the name of a file you wish to open or create: mystuff.dat [Enter] The file mystuff.dat was opened.
  • 12. Table 3 File Type Default Open Mode ofstream The file is opened for output only. (Information may be written to the file, but not read from the file.) If the file does not exist, it is created. If the file already exists, its contents are deleted (the file is truncated). ifstream The file is opened for input only. (Information may be read from the file, but not written to it.) The fileā€™s contents will be read from its beginning. If the file does not exist, the open function fails.
  • 13. Table 4 File Mode Flag Meaning ios::app Append mode. If the file already exists, its contents are preserved and all output is written to the end of the file. By default, this flag causes the file to be created if it does not exist. ios::ate If the file already exists, the program goes directly to the end of it. Output may be written anywhere in the file. ios::binary Binary mode. When a file is opened in binary mode, information is written to or read from it in pure binary format. (The default mode is text.) ios::in Input mode. Information will be read from the file. If the file does not exist, it will not be created and the open function will fail.
  • 14. Table 4 continued File Mode Flag Meaning ios::nocreate If the file does not already exist, this flag will cause the open function to fail. (The file will not be created.) ios::noreplace If the file already exists, this flag will cause the open function to fail. (The existing file will not be opened.) ios::out Output mode. Information will be written to the file. By default, the fileā€™s contents will be deleted if it already exists. ios::trunc If the file already exists, its contents will be deleted (truncated). This is the default mode used by ios::out.
  • 15. Opening a File at Declaration fstream dataFile(ā€œnames.datā€, ios::in | ios::out);
  • 16. Program 2 // This program demonstrates the opening of a file at the // time the file stream object is declared. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile("names.dat", ios::in | ios::out); cout << "The file names.dat was opened.n"; }
  • 17. Program Output with Example Input The file names.dat was opened.
  • 18. Testing for Open Errors dataFile.open(ā€œcust.datā€, ios::in); if (!dataFile) { cout << ā€œError opening file.nā€; }
  • 19. Another way to Test for Open Errors dataFile.open(ā€œcust.datā€, ios::in); if (dataFile.fail()) { cout << ā€œError opening file.nā€; }
  • 20. Closing a File ā€¢ A file should be closed when a program is finished using it.
  • 21. Program 3 // This program demonstrates the close function. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; dataFile.open("testfile.txt", ios::out); if (!dataFile) { cout << "File open error!" << endl; return; } cout << "File was created successfully.n"; cout << "Now closing the file.n"; dataFile.close(); }
  • 22. Program Output File was created successfully. Now closing the file.
  • 23. 7 Using << to Write Information to a File ā€¢ The stream insertion operator (<<) may be used to write information to a file. outputFile << ā€œI love C++ programming !ā€
  • 24. Program 4 // This program uses the << operator to write information to a file. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; char line[81]; dataFile.open("demofile.txt", ios::out); if (!dataFile) { cout << "File open error!" << endl; return; }
  • 25. Program continues cout << "File opened successfully.n"; cout << "Now writing information to the file.n"; dataFile << "Jonesn"; dataFile << "Smithn"; dataFile << "Willisn"; dataFile << "Davisn"; dataFile.close(); cout << "Done.n"; }
  • 26. Program Screen Output File opened successfully. Now writing information to the file. Done. Output to File demofile.txt Jones Smith Willis Davis
  • 28. Program 5 // This program writes information to a file, closes the file, // then reopens it and appends more information. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; dataFile.open("demofile.txt", ios::out); dataFile << "Jonesn"; dataFile << "Smithn"; dataFile.close(); dataFile.open("demofile.txt", ios::app); dataFile << "Willisn"; dataFile << "Davisn"; dataFile.close(); }
  • 29. Output to File demofile.txt Jones Smith Willis Davis
  • 30. 8 File Output Formatting ā€¢ File output may be formatted the same way as screen output.
  • 31. Program 6 // This program uses the precision member function of a // file stream object to format file output. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; float num = 123.456; dataFile.open("numfile.txt", ios::out); if (!dataFile) { cout << "File open error!" << endl; return; }
  • 32. Program continues dataFile << num << endl; dataFile.precision(5); dataFile << num << endl; dataFile.precision(4); dataFile << num << endl; dataFile.precision(3); dataFile << num << endl; }
  • 33. Contents of File numfile.txt 123.456 123.46 123.5 124
  • 34. Program 7 #include <iostream.h> #include <fstream.h> #include <iomanip.h> void main(void) { fstream outFile("table.txt", ios::out); int nums[3][3] = { 2897, 5, 837, 34, 7, 1623, 390, 3456, 12 }; // Write the three rows of numbers for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { outFile << setw(4) << nums[row][col] << " "; } outFile << endl; } outFile.close(); }
  • 35. Contents of File TABLE.TXT 2897 5 837 34 7 1623 390 3456 12
  • 37. 9 Using >> to Read Information from a File ā€¢ The stream extraction operator (>>) may be used to read information from a file.
  • 38. Program 8 // This program uses the >> operator to read information from a file. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; char name[81]; dataFile.open("demofile.txt", ios::in); if (!dataFile) { cout << "File open error!" << endl; return; } cout << "File opened successfully.n"; cout << "Now reading information from the file.nn";
  • 39. Program continues for (int count = 0; count < 4; count++) { dataFile >> name; cout << name << endl; } dataFile.close(); cout << "nDone.n"; }
  • 40. Program Screen Output File opened successfully. Now reading information from the file. Jones Smith Willis Davis Done.
  • 41. 10 Detecting the End of a File ā€¢ The eof() member function reports when the end of a file has been encountered. if (inFile.eof()) inFile.close();
  • 42. Program 9 // This program uses the file stream object's eof() member // function to detect the end of the file. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile; char name[81]; dataFile.open("demofile.txt", ios::in); if (!dataFile) { cout << "File open error!" << endl; return; } cout << "File opened successfully.n"; cout << "Now reading information from the file.nn";
  • 43. Program continues dataFile >> name; // Read first name from the file while (!dataFile.eof()) { cout << name << endl; dataFile >> name; } dataFile.close(); cout << "nDone.n"; }
  • 44. Program Screen Output File opened successfully. Now reading information from the file. Jones Smith Willis Davis Done.
  • 45. Note on eof() ā€¢ In C++, ā€œend of fileā€ doesnā€™t mean the program is at the last piece of information in the file, but beyond it. The eof() function returns true when there is no more information to be read.
  • 46. 11 Passing File Stream Objects to Functions ā€¢ File stream objects may be passed by reference to functions. bool openFileIn(fstream &file, char name[51]) { bool status; file.open(name, ios::in); if (file.fail()) status = false; else status = true; return status; }
  • 47. 12.12 More Detailed Error Testing ā€¢ All stream objects have error state bits that indicate the condition of the stream.
  • 48. Table 5 Bit Description ios::eofbit Set when the end of an input stream is encountered. ios::failbit Set when an attempted operation has failed. ios::hardfail Set when an unrecoverable error has occurred. ios::badbit Set when an invalid operation has been attempted. ios::goodbit Set when all the flags above are not set. Indicates the stream is in good condition.
  • 49. Table 6 Function Description eof() Returns true (non-zero) if the eofbit flag is set, otherwise returns false. fail() Returns true (non-zero) if the failbit or hardfail flags are set, otherwise returns false. bad() Returns true (non-zero) if the badbit flag is set, otherwise returns false. good() Returns true (non-zero) if the goodbit flag is set, otherwise returns false. clear() When called with no arguments, clears all the flags listed above. Can also be called with a specific flag as an argument.
  • 50. Program 11 // This program demonstrates the return value of the stream // object error testing member functions. #include <iostream.h> #include <fstream.h> // Function prototype void showState(fstream &); void main(void) { fstream testFile("stuff.dat", ios::out); if (testFile.fail()) { cout << "cannot open the file.n"; return; }
  • 51. Program continues int num = 10; cout << "Writing to the file.n"; testFile << num; // Write the integer to testFile showState(testFile); testFile.close(); // Close the file testFile.open("stuff.dat", ios::in); // Open for input if (testFile.fail()) { cout << "cannot open the file.n"; return; }
  • 52. Program continues cout << "Reading from the file.n"; testFile >> num; // Read the only number in the file showState(testFile); cout << "Forcing a bad read operation.n"; testFile >> num; // Force an invalid read operation showState(testFile); testFile.close(); // Close the file } // Definition of function ShowState. This function uses // an fstream reference as its parameter. The return values of // the eof(), fail(), bad(), and good() member functions are // displayed. The clear() function is called before the function // returns.
  • 53. Program continues void showState(fstream &file) { cout << "File Status:n"; cout << " eof bit: " << file.eof() << endl; cout << " fail bit: " << file.fail() << endl; cout << " bad bit: " << file.bad() << endl; cout << " good bit: " << file.good() << endl; file.clear(); // Clear any bad bits }
  • 54. Program Output Writing to the file. File Status: eof bit: 0 fail bit: 0 bad bit: 0 good bit: 1 Reading from the file. File Status: eof bit: 0 fail bit: 0 bad bit: 0 good bit: 1 Forcing a bad read operation. File Status: eof bit: 1 fail bit: 2 bad bit: 0 good bit: 0
  • 55. 13 Member Functions for Reading and Writing Files ā€¢ File stream objects have member functions for more specialized file reading and writing.
  • 57. Program -12 // This program uses the file stream object's eof() member // function to detect the end of the file. #include <iostream.h> #include <fstream.h> void main(void) { fstream nameFile; char input[81]; nameFile.open("murphy.txt", ios::in); if (!nameFile) { cout << "File open error!" << endl; return; }
  • 58. Program -12 (continued) nameFile >> input; while (!nameFile.eof()) { cout << input; nameFile >> input; } nameFile.close(); }
  • 60. The getline Member Function ā€¢ dataFile.getline(str, 81, ā€˜nā€™); str ā€“ This is the name of a character array, or a pointer to a section of memory. The information read from the file will be stored here. 81 ā€“ This number is one greater than the maximum number of characters to be read. In this example, a maximum of 80 characters will be read. ā€˜nā€™ ā€“ This is a delimiter character of your choice. If this delimiter is encountered, it will cause the function to stop reading before it has read the maximum number of characters. (This argument is optional. If itā€™s left our, ā€˜nā€™ is the default.)
  • 61. Program -13 // This program uses the file stream object's getline member // function to read a line of information from the file. #include <iostream.h> #include <fstream.h> void main(void) { fstream nameFile; char input[81]; nameFile.open("murphy.txt", ios::in); if (!nameFile) { cout << "File open error!" << endl; return; }
  • 62. Program continues nameFile.getline(input, 81); // use n as a delimiter while (!nameFile.eof()) { cout << input << endl; nameFile.getline(input, 81); // use n as a delimiter } nameFile.close(); }
  • 63. Program Screen Output Jayne Murphy 47 Jones Circle Almond, NC 28702
  • 64. Program -14 // This file shows the getline function with a user- // specified delimiter. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile("names2.txt", ios::in); char input[81]; dataFile.getline(input, 81, '$'); while (!dataFile.eof()) { cout << input << endl; dataFile.getline(input, 81, '$'); } dataFile.close(); }
  • 65. Program Output Jayne Murphy 47 Jones Circle Almond, NC 28702 Bobbie Smith 217 Halifax Drive Canton, NC 28716 Bill Hammet PO Box 121 Springfield, NC 28357
  • 66. The get Member Function inFile.get(ch);
  • 67. Program -15 // This program asks the user for a file name. The file is // opened and its contents are displayed on the screen. #include <iostream.h> #include <fstream.h> void main(void) { fstream file; char ch, fileName[51]; cout << "Enter a file name: "; cin >> fileName; file.open(fileName, ios::in); if (!file) { cout << fileName << ā€œ could not be opened.n"; return; }
  • 68. Program continues file.get(ch); // Get a character while (!file.eof()) { cout << ch; file.get(ch); // Get another character } file.close(); }
  • 69. The put Member Function ā€¢ outFile.put(ch);
  • 70. Program -16 // This program demonstrates the put member function. #include <iostream.h> #include <fstream.h> void main(void) { fstream dataFile("sentence.txt", ios::out); char ch; cout << "Type a sentence and be sure to end it with a "; cout << "period.n"; while (1) { cin.get(ch); dataFile.put(ch); if (ch == '.') break; } dataFile.close(); }
  • 71. Program Screen Output with Example Input Type a sentence and be sure to end it with a period. I am on my way to becoming a great programmer. [Enter] Resulting Contents of the File SENTENCE.TXT: I am on my way to becoming a great programmer.
  • 72. 14 Focus on Software Engineering: Working with Multiple Files ā€¢ Itā€™s possible to have more than one file open at once in a program.
  • 73. Program -17 // This program demonstrates reading from one file and writing // to a second file. #include <iostream.h> #include <fstream.h> #include <ctype.h> // Needed for the toupper function void main(void) { ifstream inFile; ofstream outFile("out.txt"); char fileName[81], ch, ch2; cout << "Enter a file name: "; cin >> fileName; inFile.open(fileName); if (!inFile) { cout << "Cannot open " << fileName << endl; return; }
  • 74. Program continues inFile.get(ch); // Get a characer from file 1 while (!inFile.eof()) // Test for end of file { ch2 = toupper(ch); // Convert to uppercase outFile.put(ch2); // Write to file2 inFile.get(ch); // Get another character from file 1 } inFile.close(); outFile.close(); cout << "File conversion done.n"; }
  • 75. Program Screen Output with Example Input Enter a file name: hownow.txt [Enter] File conversion done. Contents of hownow.txt: how now brown cow. How Now? Resulting Contents of out.txt: HOW NOW BROWN COW. HOW NOW?
  • 76. 15 Binary Files ā€¢ Binary files contain data that is unformatted, and not necessarily stored as ASCII text. file.open(ā€œstuff.datā€, ios::out | ios::binary);
  • 79. Program -18 // This program uses the write and read functions. #include <iostream.h> #include <fstream.h> void main(void) { fstream file(ā€œNUMS.DAT", ios::out | ios::binary); int buffer[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; cout << "Now writing the data to the file.n"; file.write((char*)buffer, sizeof(buffer)); file.close(); file.open("NUMS.DAT", ios::in); // Reopen the file. cout << "Now reading the data back into memory.n"; file.read((char*)buffer, sizeof(buffer)); for (int count = 0; count < 10; count++) cout << buffer[count] << " "; file.close(); }
  • 80. Program Screen Output Now writing the data to the file. Now reading the data back into memory. 1 2 3 4 5 6 7 8 9 10
  • 81. 16 Creating Records with Structures ā€¢ Structures may be used to store fixed-length records to a file. struct Info { char name[51]; int age; char address1[51]; char address2[51]; char phone[14]; }; ā€¢ Since structures can contain a mixture of data types, you should always use the ios::binary mode when opening a file to store them.
  • 82. Program -19 // This program demonstrates the use of a structure variable to // store a record of information to a file. #include <iostream.h> #include <fstream.h> #include <ctype.h> // for toupper // Declare a structure for the record. struct Info { char name[51]; int age; char address1[51]; char address2[51]; char phone[14]; };
  • 83. Program continues void main(void) { fstream people("people.dat", ios::out | ios::binary); Info person; char again; if (!people) { cout << "Error opening file. Program aborting.n"; return; } do { cout << "Enter the following information about a ā€ << "person:n"; cout << "Name: ";
  • 84. Program continues cin.getline(person.name, 51); cout << "Age: "; cin >> person.age; cin.ignore(); // skip over remaining newline. cout << "Address line 1: "; cin.getline(person.address1, 51); cout << "Address line 2: "; cin.getline(person.address2, 51); cout << "Phone: "; cin.getline(person.phone, 14); people.write((char *)&person, sizeof(person)); cout << "Do you want to enter another record? "; cin >> again; cin.ignore(); } while (toupper(again) == 'Y'); people.close(); }
  • 85. Program Screen Output with Example Input Enter the following information about a person: Name: Charlie Baxter [Enter] Age: 42 [Enter] Address line 1: 67 Kennedy Bvd. [Enter] Address line 2: Perth, SC 38754 [Enter] Phone: (803)555-1234 [Enter] Do you want to enter another record? Y [Enter] Enter the following information about a person: Name: Merideth Murney [Enter] Age: 22 [Enter] Address line 1: 487 Lindsay Lane [Enter] Address line 2: Hazelwood, NC 28737 [Enter] Phone: (704)453-9999 [Enter] Do you want to enter another record? N [Enter]
  • 86. 17 Random Access Files ā€¢ Random Access means non-sequentially accessing informaiton in a file. Figure 12-11
  • 87. Table -7 Mode Flag Description ios::beg The offset is calculated from the beginning of the file. ios::end The offset is calculated from the end of the file. ios::cur The offset is calculated from the current position.
  • 88. Table -8 Statement How it Affects the Read/Write Position File.seekp(32L, ios::beg); Sets the write position to the 33rd byte (byte 32) from the beginning of the file. file.seekp(-10L, ios::end); Sets the write position to the 11th byte (byte 10) from the end of the file. file.seekp(120L, ios::cur); Sets the write position to the 121st byte (byte 120) from the current position. file.seekg(2L, ios::beg); Sets the read position to the 3rd byte (byte 2) from the beginning of the file. file.seekg(-100L, ios::end); Sets the read position to the 101st byte (byte 100) from the end of the file. file.seekg(40L, ios::cur); Sets the read position to the 41st byte (byte 40) from the current position. file.seekg(0L, ios::end); Sets the read position to the end of the file.
  • 89. Program -21 // This program demonstrates the seekg function. #include <iostream.h> #include <fstream.h> void main(void) { fstream file("letters.txt", ios::in); char ch; file.seekg(5L, ios::beg); file.get(ch); cout << "Byte 5 from beginning: " << ch << endl; file.seekg(-10L, ios::end); file.get(ch); cout << "Byte 10 from end: " << ch << endl;
  • 90. Program continues file.seekg(3L, ios::cur); file.get(ch); cout << "Byte 3 from current: " << ch << endl; file.close(); }
  • 91. Program Screen Output Byte 5 from beginning: f Byte 10 from end: q Byte 3 from current: u
  • 92. The tellp and tellg Member Functions ā€¢ tellp returns a long integer that is the current byte number of the fileā€™s write position. ā€¢ tellg returns a long integer that is the current byte number of the fileā€™s read position.
  • 93. Program -23 // This program demonstrates the tellg function. #include <iostream.h> #include <fstream.h> #include <ctype.h> // For toupper void main(void) { fstream file("letters.txt", ios::in); long offset; char ch, again; do { cout << "Currently at position " << file.tellg() << endl; cout << "Enter an offset from the beginning of the file: "; cin >> offset;
  • 94. Program continues file.seekg(offset, ios::beg); file.get(ch); cout << "Character read: " << ch << endl; cout << "Do it again? "; cin >> again; } while (toupper(again) == 'Y'); file.close(); }
  • 95. Program Output with Example Input Currently at position 0 Enter an offset from the beginning of the file: 5 [Enter] Character read: f Do it again? y [Enter] Currently at position 6 Enter an offset from the beginning of the file: 0 [Enter] Character read: a Do it again? y [Enter] Currently at position 1 Enter an offset from the beginning of the file: 20 [Enter] Character read: u Do it again? n [Enter]
  • 96. 18 Opening a File for Both Input and Output ā€¢ You may perform input and output on an fstream file without closing it and reopening it. fstream file(ā€œdata.datā€, ios::in | ios::out);
  • 97. Program 24 // This program sets up a file of blank inventory records. #include <iostream.h> #include <fstream.h> // Declaration of Invtry structure struct Invtry { char desc[31]; int qty; float price; }; void main(void) { fstream inventory("invtry.dat", ios::out | ios::binary); Invtry record = { "", 0, 0.0 };
  • 98. Program continues // Now write the blank records for (int count = 0; count < 5; count++) { cout << "Now writing record " << count << endl; inventory.write((char *)&record, sizeof(record)); } inventory.close(); }
  • 99. Program Screen Output Now writing record 0 Now writing record 1 Now writing record 2 Now writing record 3 Now writing record 4
  • 100. Program -25 // This program displays the contents of the inventory file. #include <iostream.h> #include <fstream.h> // Declaration of Invtry structure struct Invtry { char desc[31]; int qty; float price; }; void main(void) { fstream inventory("invtry.dat", ios::in | ios::binary); Invtry record = { "", 0, 0.0 };
  • 101. Program continues // Now read and display the records inventory.read((char *)&record, sizeof(record)); while (!inventory.eof()) { cout << "Description: "; cout << record.desc << endl; cout << "Quantity: "; cout << record.qty << endl; cout << "Price: "; cout << record.price << endl << endl; inventory.read((char *)&record, sizeof(record)); } inventory.close(); }
  • 102. Here is the screen output of Program 12-25 if it is run immediately after Program 12-24 sets up the file of blank records. Program Screen Output Description: Quantity: 0 Price: 0.0 Description: Quantity: 0 Price: 0.0 Description: Quantity: 0 Price: 0.0 Description: Quantity: 0 Price: 0.0 Description: Quantity: 0 Price: 0.0
  • 103. Program -26 // This program allows the user to edit a specific record in // the inventory file. #include <iostream.h> #include <fstream.h> // Declaration of Invtry structure struct Invtry { char desc[31]; int qty; float price; }; void main(void) {
  • 104. Program continues fstream inventory("invtry.dat", ios::in | ios::out | ios::binary); Invtry record; long recNum; cout << "Which record do you want to edit?"; cin >> recNum; inventory.seekg(recNum * sizeof(record), ios::beg); inventory.read((char *)&record, sizeof(record)); cout << "Description: "; cout << record.desc << endl; cout << "Quantity: "; cout << record.qty << endl; cout << "Price: "; cout << record.price << endl; cout << "Enter the new data:n"; cout << "Description: ";
  • 105. Program continues cin.ignore(); cin.getline(record.desc, 31); cout << "Quantity: "; cin >> record.qty; cout << "Price: "; cin >> record.price; inventory.seekp(recNum * sizeof(record), ios::beg); inventory.write((char *)&record, sizeof(record)); inventory.close(); }
  • 106. Program Screen Output with Example Input Which record do you ant to edit? 2 [Enter] Description: Quantity: 0 Price: 0.0 Enter the new data: Description: Wrench [Enter] Quantity: 10 [Enter] Price: 4.67 [Enter]
  • 107. References 1. www.tutorialspoint.com/cprogramming/c_pointers.htm 2. www.cprogramming.com/tutorial/c/lesson6.html 3. pw1.netcom.com/~tjensen/ptr/pointers.html 4. Programming in C by yashwant kanitkar 5.ANSI C by E.balagurusamy- TMG publication 6.Computer programming and Utilization by sanjay shah Mahajan Publication 7.www.cprogramming.com/books.html 8.en.wikipedia.org/wiki/C_(programming_language)