-
Notifications
You must be signed in to change notification settings - Fork 0
/
getdata.c
38 lines (36 loc) · 1.33 KB
/
getdata.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
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "headertoko.h"
int getdata() {
FILE *master, *stock;
master = fopen("masterbarang.dat", "rb");
stock = fopen("stok.dat", "rb");
struct masterbarang mstr = {0, "", 0};
struct stok stk = {0, 0, 0};
if ((master == NULL) || (stock == NULL)) {
printf("Couldn't load file");
} else {
printf("======================== DATA BARANG =========================\n");
printf("|%-5s |%-25s |%-9s |%-9s |%-5s|\n", "Kode", "Barang", "Hrg Jual", "Hrg Beli", "Stock");
printf("|-------------------------------------------------------------|\n");
int index = 0;
while (!feof(master)) {
fread(&mstr, sizeof(struct masterbarang), 1, master);
fread(&stk, sizeof(struct stok), 1, stock);
if (mstr.kode != index) {
printf("|%-5d |%-25s |%-9d |%-9d |%-5d|\n", mstr.kode, mstr.nama, stk.hargajual, mstr.hargabeli, stk.jumlah);
index = mstr.kode;
}
}
printf(" =============================================================\n");
}
printf("Tekan enter untuk kembali ...\n");
_getch();
fclose(master);
fclose(stock);
}