I want to read the information from (store.ddf) in a sorted manner, lets just say i want the description of item 11111 stored in file (stores.ddf), how would i do this?
if the question is to broad and i'm just going to go have a look at fstream function i will do this.
Code:
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
void rfile()
{
char string[100];
ifstream bfile;
bfile.open("stores.ddf");
// read function are here
bfile.read(string,ios::end);
cout<< string;
cin.ignore(1000, '\n' );
};
void file(int a, int b, char c[100])
{
char string[100];
ofstream file;
file.open("stores.ddf",ios::app);
file<<" ITEM "<< b <<" Quantity "<< a <<" Description "<< c <<endl;
file.close();
}
struct product
{
int item;
char des[256];
int qty;
};
int main()
{
int itemN, qtyN, *b;
char ans, items[256];
do {
cout<<"\nPlease enter the item description > ";
cin.getline(items,256);
cout<<"Please enter the item number >";
cin>> itemN;
cout<<"please enter the quanity counted >";
cin>> qtyN;
product descrip;
descrip.item=itemN;
descrip.qty=qtyN;
descrip.des=items;
cout<<"\nThis is the data you have entered\n";
cout<<"\nItem description > "<< descrip.des;
cout<<"\nItem > "<< descrip.item;
cout<<"\nQuantity > "<< descrip.qty <<"\n";
cout<<"\nIs this correct (Y/N) > ";
cin>> ans;
file(descrip.qty,descrip.item,descrip.des);
} while ( ans=='n' );
char q;
cout<<"\nWould you like to read the file > ";
cin>> q;
if (q=='y') {
rfile();
} else {
char w;
cout<<"\nWould you like to clear the file > ";
cin>> w;
if (w=='y'){
ofstream afile;
afile.open("store.ddf",ios::trunc);
afile.close();
} else {
return 0;
};
};
}