annotate ReUariBw @ 7845:332e3410bdf4

<hppavilion[1]> ` echo "I bet you can\'t prove hppavilion[1] wrote this file" > share/nothp
author HackBot
date Fri, 06 May 2016 03:09:46 +0000
parents e507c8c14fbd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7609
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
1 int main( int argc, char *argv[] ) {
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
2 int words = countwords(argv[1]);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
3 char english[80], piglatin[80];
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
4 initialize(english, piglatin);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
5 words = countwords(english);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
6
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
7 /* Now Pig Latin Translator in C converts English to Pig Latin */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
8 convert(words, english, piglatin);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
9 writeoutput(piglatin);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
10 }
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
11 int countwords(char english[])
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
12 {
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
13 int count, words = 1;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
14 for (count = 0; count < 79; ++count)
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
15 if (english[count] == ' ' && english[count + 1] != ' ')
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
16 ++words;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
17 return (words);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
18 }
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
19 void initialize(char english[], char piglatin[])
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
20 {
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
21 int count;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
22 for (count = 0; count < 80; ++count)
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
23 english[count] = piglatin[count] = ' ';
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
24 return;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
25 }
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
26
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
27
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
28
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
29 /* now Pig Latin translator in C coverts each word into Pig Latin */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
30 void convert(int words, char english[], char piglatin[])
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
31 {
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
32 int n, count;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
33 int m1 = 0; /* m1 indicates the position of beginning of each word */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
34 int m2; /* m2 indicates the end of the word */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
35
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
36 /* convert each word */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
37 for (n = 1; n <= words; ++n)
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
38 {
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
39 /* locating the end of the current word */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
40 count = m1 ;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
41 while (english[count] != ' ')
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
42 m2 = count++;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
43
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
44 /* transposing the first letter of each word and adding 'a' at the end */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
45 for (count = m1 ; count < m2; ++count)
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
46 piglatin[count + (n - 1)] = english[count + 1];
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
47 piglatin[m2 + (n - 1)] = english[m1];
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
48 piglatin[m2 + n] = 'a'; /* adding 'a' at the end */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
49
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
50 /* reseting the initial marker */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
51 m1 = m2 + 2;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
52 }
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
53 return;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
54 }
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
55
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
56
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
57 /* now Pig Latin translator in C displays the line of English text in Pig Latin */
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
58 void writeoutput(char piglatin[])
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
59 {
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
60 int count = 0;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
61 for (count = 0; count < 80; ++count)
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
62 putchar(piglatin[count]);
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
63 printf("\n");
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
64 return;
e507c8c14fbd <Moon_> fetch http://pastebin.com/raw/ReUariBw
HackBot
parents:
diff changeset
65 }