-
Notifications
You must be signed in to change notification settings - Fork 0
/
parts.c
59 lines (52 loc) · 907 Bytes
/
parts.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
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
struct items
{
int num;
char name[50];
};
int main(void)
{
struct items item[5];
FILE *file;
int NUM,i,j;
char NAME[50];
int exist=false;
for(i=0;i<5;i++)
{
printf("Enter the %i Item Code : ",i+1);
scanf("%i",&NUM);
printf("Enter the %i Item Name : ",i+1);
scanf("%s",&NAME);
for(j=0;j<=i;j++)
{
if(strcmp(item[j].name, NAME) == 0)
{
printf("This Item is already exist..\n");
exist =true;
i--;
break;
}
}
if(!exist)
{
item[i].num = NUM;
strcpy(item[i].name, NAME);
}
exist = false;
}
file = fopen("items.dat","w+");
for(i=0;i<5;i++)
{
fprintf(file,"%i\t%s\n",item[i].num,item[i].name);
}
fclose(file);
file = fopen("items.dat","r+");
for(i=0;i<5;i++)
{
while(fscanf(file,"%i\t%s",&NUM,&NAME)!=EOF)
printf("%i\t%s\n",NUM,NAME);
}
fclose(file);
}