-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitemstructure.c
More file actions
84 lines (63 loc) · 2.01 KB
/
itemstructure.c
File metadata and controls
84 lines (63 loc) · 2.01 KB
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
83
84
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void addItem(); // Gowtham Thulasi
void editItem(); //Vikhnesh S
void deleteItem(); //Akshay Prasad
void viewItem(); //Lakshmi Anil
int CheckitemcodeName(int item_code,char item_name[]); //Gowtham Thulasi
struct itemfile{
int item_code; //Item Code
char item_name[50]; //Item Name
float it_price; //Item Price
int it_os; //Opening Stock
int it_cs; //Closing Stock
//opening stock and closing stockum same value venam enter cheyyan
};
int main(){
}
void addItem() {
FILE *fp;
struct itemfile item;
printf("\n Enter Item Code: ");
scanf("%d", &item.item_code);
printf("\n Enter the Item Name: ");
scanf("%s", item.item_name);
printf("\n Enter the Item Price: ");
scanf("%f", &item.it_price);
printf("\n Enter the Opening Stock: ");
scanf("%d", &item.it_os);
item.it_cs = item.it_os;
if (CheckitemcodeName(item.item_code, item.item_name)) {
printf("\n Error: Item Code or Name already exists!");
return;
}
fp = fopen("itemfile.dat", "ab+");
if (fp == NULL) {
printf("\n Error opening the file..");
return;
}
fwrite(&item, sizeof(item), 1, fp);
printf("\n Item added successfully!");
fclose(fp);
}
// we must ensure that no duplicated item code or item name should be added to the file so that it should be more reliable
int CheckitemcodeName(int item_code, char item_name[]) {
FILE *fp;
struct itemfile item;
int found = 0;
fp = fopen("itemfile.dat", "rb");
if (fp == NULL) {
printf("\n Error opening the file..");
return 0;
}
while (fread(&item, sizeof(item), 1, fp)) {
if (item.item_code == item_code || strcmp(item.item_name, item_name) == 0) {
found = 1;
break;
}
}
fclose(fp);
return found;
}
// filename = itemfile.dat ethu venee kodukkan