/home/toolbox/public_html/solutions/4/492/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2020-04-21
19 * Purpose: fun
20 * Problem: 492 - Pig-Latin
21 */
22
23 /*
24 * This template reads lines of data at a time until end of file.
25 */
26
27 #define MAX_LINE 100026
28 #define NOTHING '0'
29
30 char line[MAX_LINE];
31
32 void init()
33 {
34 /* FUNCTION init */
35 } /* FUNCTION init */
36
37 void dump()
38 {
39 /* FUNCTION dump */
40 } /* FUNCTION dump */
41
42 int getInput()
43 {
44 /* FUNCTION getInput */
45 int dataReadFlag;
46
47 fgets(line, MAX_LINE, stdin);
48 if (feof(stdin))
49 dataReadFlag = FALSE;
50 else
51 {
52 /* something to read */
53 dataReadFlag = TRUE;
54 line[strlen(line)-1] = 0;
55 } /* something to read */
56 return (dataReadFlag);
57 } /* FUNCTION getInput */
58
59 int doWord(int a)
60 {
61 /* FUNCTION doWord */
62 char save = NOTHING;
63 switch (line[a])
64 {
65 /* switch */
66 case 'A':
67 case 'E':
68 case 'I':
69 case 'O':
70 case 'U':
71 case 'a':
72 case 'e':
73 case 'i':
74 case 'o':
75 case 'u':
76 printf("%c", line[a]);
77 break;
78 default:
79 save = line[a];
80 break;
81 } /* switch */
82 a++;
83 while (isalpha(line[a]))
84 {
85 /* while */
86 printf("%c", line[a]);
87 a++;
88 } /* while */
89 if (NOTHING != save)
90 {
91 printf("%c", save);
92 }
93 printf("ay");
94 return (a-1);
95 } /* FUNCTION doWord */
96
97 void process()
98 {
99 /* FUNCTION process */
100 int i;
101 int sln;
102
103 sln = strlen(line);
104 for (i=0; sln>i; i++)
105 {
106 /* for each word */
107 if (isalpha(line[i]))
108 {
109 /* found a letter - start a new word */
110 i = doWord(i);
111 } /* found a letter - start a new word */
112 else
113 {
114 /* non-letter */
115 printf("%c", line[i]);
116 } /* non-letter */
117 } /* for each word */
118 printf("\n");
119 } /* FUNCTION process */
120
121 int main()
122 {
123 /* main */
124 int moreToDo;
125
126 init();
127 moreToDo = getInput();
128 while (moreToDo)
129 {
130 /* while */
131 process();
132 moreToDo = getInput();
133 } /* while */
134
135 return EXIT_SUCCESS;
136 } /* main */
137