Pig Latin Translator in C

0
7739

Pig Latin translator, often used by children as a game, is an encoded form of English language. It transposes the first sound or the first letter of an English word to the end of the word, and then adds the letter ‘a. So, when the word ‘dog’ is passed through Pig Latin Translator, it becomes ‘ogda‘, ‘computer’ becomes ‘omputerca‘, and so on. The word ‘piglatin’ becomes ‘iglatinpa‘ or ‘igpa atinla‘ if used or spelled as two separate words.

The program for Pig Latin Translator in C presented here will accept a line of text in English, and then give out the corresponding text in Pig Latin as output. In the source code, I have mentioned comments in various sections of the code to help you understand the program better. But before going through the C source code, here, I have enlisted the features and working procedure or computational strategy of this Pig Latin Translator program.

Features of Pig Latin Translator in C:

Pig Latin Translator in C

  1. The program accepts only a line of text in English, and it will be translated to Pig Latin.
  2. Each text message can be typed on one 80-column line only, with a single black space between each words.
  3. The message sent to the program should not exceed 80 characters; it should be less than that as the original message will be lengthened somewhat by Pig Latin Translator.
  4. For simplicity, the Pig Latin Translator in C transposes only the first letter of each word – not the first sound.
  5. Capitalization and punctuations are ignored.

Working Procedure of Pig Latin Translator in C:

Pig Latin Translator in C

The program will use two character arrays, namely english and piglatinone containing the original message, and the other containing the translated Pig Latin text. The overall working procedure of the Pig Latin Translator is simple and straightforward; it follows the following major steps:

  1. Both arrays are initialized assigning blank spaces to all the elements contained by them.
  2. Ask for the message or line of text from the user.
  3. Determine the number of words in the line of text. This is done by counting the number of single black spaces that are followed by a non-blank space.
  4. Rearrange the words into Pig Latin, following the steps mentioned below for each word.
    • Locate the end of the word.
    • Then, transpose the first letter to the end of the word, and add an ‘a‘.
    • Locate the beginning of the next word, follow above step.
  5. Display the translated line of text as output.

This program – Pig Latin Translator in C continues the above steps repeatedly until it reads a line of text whose first three letters are ‘END‘ or ‘end‘. To make use of this overall working procedure, two markers, namely m1 and m2 are used in the program. The first marker m1 indicates the position of the beginning of each word, while the second marker m2 indicates the end of the word within the original line of text.

Following are the main program variables used in Pig Latin Translator in C:

  • english – a one-dimensional array containing the original message/line of text
  • piglatin – a one-dimensional array containing the translated message/line of text
  • words – an integer variable that counts the number of words in the given message/line of text
  • n – an integer variable used as a word counter
  • count – an integer variable that counts character within each line
  • m1 – an integer variable that indicates the position of the beginning of each word
  • m2 – an integer variable that indicates the end of the word

Pig Latin Translator in C Source Code:

Copy the source code for Pig Latin Translator in Code::Blocks IDE using GCC compiler, and you’ll get an output as shown below.

Pig Latin Translator in C Output

As already stated in the features, the Pig Latin translator in C does not have any special accommodations for double-letter sounds (th, sh), uppercase letters and punctuation marks. These have been left as rooms for improvements in the source code for readers. Your queries and feedback regarding Pig Latin translator can be brought up to me from the comments box below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here