#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;
struct tm* tt;
struct customer {
char phone[22];
char name[20];
char address[50];
};
struct reservation {
int yearday, month, date;
int customerid[20];
};
reservation rese[366];
void addcust(const char*fname,const char *_phone,const char *_name,const char* adres) {
ofstream out(fname,ios_base::app);
out << _phone << " " << _name << " " << adres << "\n";
out.close();
cout << "Succefuly add customer!!!\n";
}
void ReadCustomerFile(const char* fname, customer* custs,int *size)
{
*size = 0;
FILE* fl;
fl = fopen(fname, "r+");
if (!fl)
{
cout << "File not found!!!\n";
return;
}
char _ph[22];
char _nm[20];
char adrs[50];
while (fscanf(fl,"%s%s", _ph, _nm)==2)
{
cout << _ph << " " << _nm << endl;
fscanf(fl, "\n");
fgets(adrs, 50, fl);
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");
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