This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nato_file_translator.c
81 lines (73 loc) · 1.59 KB
/
nato_file_translator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char isterm(char *term)
{
const char *nato[] = {
"Alfa", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot",
"Golf", "Hotel", "India", "Juliett", "Kilo", "Lima",
"Mike", "November", "Oscar", "Papa", "Quebec", "Romeo",
"Sierra", "Tango", "Uniform", "Victor", "Whiskey",
"Xray", "Yankee", "Zulu"};
int x;
const char *n;
char *t;
for (x = 0; x < 26; x++)
{
n = nato[x];
t = term;
while (*n != '\0')
{
if ((*n | 0x20) != (*t | 0x20))
break;
n++;
t++;
}
if (*n == '\0')
return (*nato[x]);
}
return ('\0');
}
int main(int argc, char *argv[])
{
FILE *n;
char word[64];
int ch, offset;
if (argc < 2)
{
fprintf(stderr, "Please supply a text file arguments\n");
exit(1);
}
n = fopen(argv[1], "r");
if (n == NULL)
{
fprintf(stderr, "Unable to open '%s'\n", argv[1]);
exit(1);
}
offset = 0;
while ((ch = fgetc(n)) != EOF)
{
if (isalpha(ch))
{
word[offset] = ch;
offset++;
if (offset >= 64)
{
fprintf(stderr, "Buffer overflow\n");
return (1);
}
}
else
{
if (offset > 0)
{
word[offset] = '\0';
putchar(isterm(word));
offset = 0;
}
}
}
putchar('\n');
fclose(n);
return (0);
}