-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.c
82 lines (73 loc) · 1.58 KB
/
5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<stdio.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include "2.h"
#include "3.h"
#include "structures.h"
int find_bill(int bill_num)
{
int i=0;
FILE *file_ptr;
file_ptr = fopen("data.txt","rb");
struct bill tmp_bill;
if(file_ptr==NULL)
{
printf("FILE NOT OPENED\n");
return -2;
}
else
{
fread(&tmp_bill,sizeof(struct bill),1,file_ptr);
while(!feof(file_ptr))
{
if(tmp_bill.bill_no==bill_num)
{
fclose(file_ptr);
return (ftell(file_ptr) - sizeof(struct bill));
}
fread(&tmp_bill,sizeof(struct bill),1,file_ptr);
}
}
fclose(file_ptr);
return -1;
}
void search_bill_by_name(char* cust_name)
{
char* name=(char*)calloc(100,sizeof(char));
int i = 0;
FILE *file_ptr;
file_ptr = fopen("data.txt","rb");
struct bill tmp_bill;
if(file_ptr==NULL)
{
printf("\nFILE NOT OPENED\n");
}
else
{
int* arr1=(int*)calloc(10,sizeof(int));
fread(&tmp_bill,sizeof(struct bill),1,file_ptr);
while(!feof(file_ptr))
{
if(strcmp(tmp_bill.customer_name,cust_name)==0)
{
arr1[i]=tmp_bill.bill_no;
i++;
}
fread(&tmp_bill,sizeof(struct bill),1,file_ptr);
}
if(i==0)
{
fclose(file_ptr);
printf("\nNot Found\n");
}
else
{
fclose(file_ptr);
for(int j=0;j<i;j++)
{
display_bill(read_bill(find_bill(arr1[j])));
}
}
}
}