-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.h
58 lines (50 loc) · 992 Bytes
/
utilities.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
int indexOf(char a, char *s)
{
for(int i=0;i<strlen(s);i++)
if(toupper(a)==s[i])
return i;
return -1;
}
int compareChars(char a,char b, char *ABC)
{
return indexOf(a,ABC)-indexOf(b,ABC);
}
int strCompare(char *a, char *b, char *ABC)
{
for(int i=0,j=0;i<strlen(a)&&j<strlen(b);i++,j++)
{
int x=compareChars(a[i],b[j],ABC);
if(x!=0)
return x;
}
return 0;
}
void printError(const char *fileName)
{
printf("El archivo %s no existe\n",fileName);
exit(0);
}
int readStrings(const char *fileName, char **words)
{
FILE * file = freopen(fileName, "r",stdin);
if(!file)
printError(fileName);
int len=0;
while(scanf("%s",words[len++])!=EOF);
fclose(file);
return len-1;
}
void readAlphabet(const char *fileName,char *ABC)
{
FILE * file = freopen(fileName, "r",stdin);
if(!file)
printError(fileName);
int i=0;
while(scanf("%s",&(ABC[i++]))!=EOF);
fclose(file);
}
void writeStrings(char **words, int len)
{
for(int i=0;i<len;i++)
printf("%s\n", words[i]);
}