Question

In C please

Pig latin has two very simple rules:

  1. If a word starts with a consonant move the first letter(s) of the word, till you reach a vowel, to the end of the word and add "ay" to the end.
    • have ➞ avehay
    • cram ➞ amcray
    • take ➞ aketay
    • cat ➞ atcay
    • shrimp ➞ impshray
    • trebuchet ➞ ebuchettray
  2. If a word starts with a vowel add "yay" to the end of the word.
    • ate ➞ ateyay
    • apple ➞ appleyay
    • oaken ➞ oakenyay
    • eagle ➞ eagleyay

Write a program that reads from a file of words separated by line breaks and translates them into Pig Latin. The filename will be given as a command line argument. If the word starts with a capital letter, that capitalization should be preserved.

For example, given a file with:

flag
Apple
button

Your program should print this to the console

agflay
Appleyay
uttonbaynts 155E Technical Problems Here are your two technical problems. Please name them pig_latin.c and array_of_multiples.c, resp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Whether you face any problem or need any modification then share with me in the comment section, I'll happy to help you.

Program:

#include<stdio.h>
#include<string.h>
#include<ctype.h>

//function prototypes
int isVowel(char);
int isConsonant(char);
void convert(char*, char*);

//main function
int main()
{
FILE *f;
f = fopen("words.txt", "r");
if(f==NULL)
{
printf("File not exist!\n");
return 1;
}

char word[20], mword[20];

while(1)
{
fscanf(f, "%s", word);
if(feof(f)) break;
convert(word, mword);
printf("%s\n", mword);
}

fclose(f);
}

//function check c is vowel
int isVowel(char c)
{
if(!isalpha(c)) return 0;

switch(c)
{
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':

return 1;
}
return 0;
}

//function check c is consonant
int isConsonant(char c)
{
if(!isalpha(c) || isVowel(c)) return 0;
return 1;
}

void convert(char word[], char mword[])
{
//variable declaration
char ch, *p;
int i, n, cap=0;

//calculate length of a string
n = strlen(word);
strcpy(mword, word);

//check whether the word starting with vowel
if(isVowel(mword[0]))
{
strcat(mword, "yay");
}
//the word starting with consonant
else
{
do
{
ch = mword[0];
for(i=0; i<n-1; i++)
mword[i] = mword[i+1];
mword[n-1] = ch;
}while(isConsonant(mword[0]));
strcat(mword, "ay");
}
}

words.txt

flag
Apple
button

Output:

agflay
Appleyay
uttonbay

Add a comment
Know the answer?
Add Answer to:
In C please Pig latin has two very simple rules: If a word starts with a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C please Create a program that takes two integers as command line arguments (num, length)...

    In C please Create a program that takes two integers as command line arguments (num, length) and outputs a list of the first length multiples of num. num should be included in the returned array. For example: ./a.out 7 5 -> [7, 14, 21, 28, 35] ./a.out 12, 10 -> [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] ./a.out 17, 6 -> [17, 34, 51, 68, 85, 102] Ma Word starts with a vowel add "yay" to the...

  • In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need...

    In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1. If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end. 2. If the word begins with...

  • Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin....

    Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin.” The rules used by Pig Latin are as follows: • If a word begins with a vowel, just as "yay" to the end. For example, "out" is translated into "outyay". • If it begins with a consonant, then we take all consonants before...

  • Pig Latin Translator in Java The goal here is to read in the characters stored in...

    Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin.” The rules used by Pig Latin are as follows: • If a word begins with a vowel, just as "yay" to the end. For example, "out" is translated into "outyay". • If it begins with a consonant, then we take all consonants before...

  • Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will...

    Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case insensitive. You must write the function translate() that takes in a single English word and returns its Pig Latin translation. Remember translate must take only one word as input. #############################################################...

  • Pig Latin program using Linked Lists C++

    Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are asfollows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".b. If the string does not begin with a vowel, first ass "-" at the end of the string....

  • Correct the syntax errors to allow the code to pass all of the provided doctests. You...

    Correct the syntax errors to allow the code to pass all of the provided doctests. You may have heard of "Pig Latin," a set of rules for modifying regular English to render it unintelligible to those who do not know the rules. This problem asks you to fix a function that will convert an English word to Pig Latin The rules for converting a word to Pig Latin are as follows: 1. If the word starts with a vowel, add...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • Hello! i need a program in C that uses FILE*! The instructions are below! Please dont...

    Hello! i need a program in C that uses FILE*! The instructions are below! Please dont copy paste another chegg post! Thank you! Will leave positive review! I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT