-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeletebarang.c
More file actions
71 lines (68 loc) · 2.12 KB
/
deletebarang.c
File metadata and controls
71 lines (68 loc) · 2.12 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "custom.h"
void deletebarang(){
FILE *f;
f=fopen("barang.dat","rb+");
if (f==NULL)
{
printf("Tidak dapat membuka file.\n");
fclose(f);
system("cls");
}else{
while (1)
{
lihatbarang();
printf("Masukkan kode barang yang ingin dihapus: ");
char kode[7];
int found=0;
scanf("%s", kode);
if (!strcmp(kode,"0000"))
{
system("cls");
break;
}
struct barang barang;
f=fopen("barang.dat","rb+");
while (!feof(f))
{
if (fread(&barang, sizeof(struct barang), 1, f))
{
if (strcmp(barang.kode, kode) == 0)
{
found=1;
printf("Anda Yakin Ingin Menghapus barang %s? (Y/N): ", barang.nama);
char pilih[1];
scanf("%s", pilih);
int posisi=atoi(barang.kode);
if (strcmp(pilih,"N") == 0)
{
printf("Batal Menghapus Barang\n");
break;
}
else if(strcmp(pilih,"Y")==0){
strcpy(barang.kode, " ");
strcpy(barang.nama, " ");
barang.harga=0;
barang.hargabeli=0;
barang.jumlah=0;
fseek(f, (posisi-1)*sizeof(struct barang), SEEK_SET);
fwrite(&barang, sizeof(struct barang), 1, f);
break;
}
else{
printf("Masukkan Input Yang Benar!\n");
}
}
}
}
if (found==0)
{
printf("Kode barang tidak ditemukan\n");
}
fclose(f);
}
}
fclose(f);
}