#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <conio.h>
using namespace std;
time_t t; // t passed as argument in function time()
struct tm* tt; // declaring variable for localtime()
struct customer {
char phone[22];
char name[20];
char address[50];
};
struct reservation {
int yearday, month, date;
int customerid[20];//note that array index is hotel room number.
};
reservation rese[366];
void addcust(const char*fname,const char *_phone,const char *_name,const char* adres) {
//Create file Handler
//fname-file name(.txt) _phone-phone customer...
ofstream out(fname,ios_base::app);//Create file
out << _phone << " " << _name << " " << adres << "\n";//Write date to file
out.close();//Close file
cout << "Succefuly add customer!!!\n";
}
//Example demo
//Read Customer
void ReadCustomerFile(const char* fname, customer* custs,int *size)//Read Date to array customers
{
//*size=pointer int size of array customer(count customers)
*size = 0;
FILE* fl;//File handler
fl = fopen(fname, "r+");//Open file C mode
if (!fl)
{
cout << "File not found!!!\n";
return;
}
char _ph[22];
char _nm[20];
char adrs[50];
//Read customers
while (fscanf(fl,"%s%s", _ph, _nm)==2)
{
cout << _ph << " " << _nm << endl;
fscanf(fl, "\n");
fgets(adrs, 50, fl);//Read Adress
strcpy(custs[*size].phone, _ph);
strcpy(custs[*size].name, _nm);
strcpy(custs[*size].address, adrs);
*size = *size + 1;
}
fclose(fl);
}
int main()
{
addcust("Customer.txt", "+123456789", "Chris", "USA");
addcust("Customer.txt", "+123457789", "Jon", "Canada");
addcust("Customer.txt", "+123456789", "Cumir", "Russia");
addcust("Customer.txt", "+123454789", "Dayan", "Cuba");
//Example read
customer* ct = new customer[366];
int size = 0;
ReadCustomerFile("Customer.txt", ct, &size);
for (int i = 0; i < size; i++)
{
cout << ct[i].phone << " " << ct[i].name << " " << ct[i].address << endl;
}
return 0;
}
Comments
Leave a comment