-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewchar.h
107 lines (83 loc) · 2 KB
/
newchar.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//function to read file User_error and save its contents according to number in different file
//
//
//
struct data
{
char character;
int present;
};
char test;
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,no=0;
int saver()
{
// printf("ram1");
struct data target[26];
FILE * fp;
FILE * fp1;
char * test = NULL;
size_t len = 0;
ssize_t read;
fp = fopen("User_error.txt", "r");
if (fp == NULL)
// exit(EXIT_FAILURE);
//printf("ram2\n") ;
target[0].character='a';
target[1].character='b';
target[2].character='c';
target[3].character='d';
target[4].character='e';
target[5].character='f';
target[6].character='g';
target[7].character='h';
target[8].character='i';
target[9].character='j';
target[10].character='k';
target[11].character='l';
target[12].character='m';
target[13].character='n';
target[14].character='o';
target[15].character='p';
target[16].character='q';
target[17].character='r';
target[18].character='s';
target[19].character='t';
target[20].character='u';
target[21].character='v';
target[22].character='w';
target[23].character='x';
target[24].character='y';
target[25].character='z';
//to inislise value of target.character == 0
fp1 = fopen("scoreboard.txt", "r");
for(no=0;no<26;no++)
{
target[no].present=0;
//printf("%d tar",&d);
}
if(fp1!=NULL ){
//printf("%d",no);
for(no=0;no<26;no++)
fscanf(fp1,"%c%d\n",&target[no].character,&target[no].present);
}
fclose(fp1);
// printf("%c",target[0].character);
while ((read = getline(&test, &len, fp)) != -1) {
// printf("Retrieved line of length %zu:\n", read);
// printf("%s",test);
for(no=0;no<26;no++){
if(*test==target[no].character){
target[no].present++;
//printf("%c",target[no].character);
}}
}
fclose(fp);
// if (test)
// free(test);
// exit(EXIT_SUCCESS);
fp1 = fopen ("scoreboard.txt", "w+");
for(no=0;no<26;no++)
fprintf(fp1,"%c%d\n",target[no].character,target[no].present);
fclose(fp1);
}
//FILE * fp;