# HG changeset patch # User HackBot # Date 1461889910 0 # Node ID e507c8c14fbd6a80ffe4d62aa7254e0b47d793eb # Parent 4f3b80f966b3771237ae83c535f37bca759e78b5 fetch http://pastebin.com/raw/ReUariBw diff -r 4f3b80f966b3 -r e507c8c14fbd ReUariBw --- /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