changeset 7609:e507c8c14fbd

<Moon_> fetch http://pastebin.com/raw/ReUariBw
author HackBot
date Fri, 29 Apr 2016 00:31:50 +0000
parents 4f3b80f966b3
children 0e9164f2d960
files ReUariBw
diffstat 1 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ReUariBw	Fri Apr 29 00:31:50 2016 +0000
@@ -0,0 +1,65 @@
+int main( int argc, char *argv[] ) {
+    int words = countwords(argv[1]);
+     char english[80], piglatin[80];
+     initialize(english, piglatin);
+     words = countwords(english);
+
+        /* Now Pig Latin Translator in C converts English to Pig Latin */
+        convert(words, english, piglatin);
+        writeoutput(piglatin);
+}
+int countwords(char english[])
+{
+    int count, words = 1;
+    for (count = 0; count < 79; ++count)
+    if (english[count] == ' ' && english[count + 1] != ' ')
+        ++words;
+    return (words);
+}
+void initialize(char english[], char piglatin[])
+{
+    int count;
+    for (count = 0; count < 80; ++count)
+        english[count] = piglatin[count] = ' ';
+    return;
+}
+
+
+
+/* now Pig Latin translator in C coverts each word into Pig Latin */
+void convert(int words, char english[], char piglatin[])
+{
+    int n, count;
+    int m1 = 0; /* m1 indicates the position of beginning of each word */
+    int m2; /* m2 indicates the end of the word */
+
+    /* convert each word */
+    for (n = 1; n <= words; ++n)
+    {
+        /* locating the end of the current word */
+        count = m1 ;
+        while (english[count] != ' ')
+            m2 = count++;
+
+        /* transposing the first letter of each word and adding 'a' at the end */
+        for (count = m1 ; count < m2; ++count)
+            piglatin[count + (n - 1)] = english[count + 1];
+        piglatin[m2 + (n - 1)] = english[m1];
+        piglatin[m2 + n] = 'a'; /* adding 'a' at the end */
+
+        /* reseting the initial marker */
+        m1 = m2 + 2;
+    }
+    return;
+}
+
+
+/* now Pig Latin translator in C displays the line of English text in Pig Latin */
+void writeoutput(char piglatin[])
+{
+    int count = 0;
+    for (count = 0; count < 80; ++count)
+        putchar(piglatin[count]);
+    printf("\n");
+    return;
+}
\ No newline at end of file