Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IMPORTANT: PROGRAM IN C LANGUAGE, NOT C++ Program in C language please , prefera

ID: 3825139 • Letter: I

Question

IMPORTANT: PROGRAM IN C LANGUAGE, NOT C++

Program in C language please , preferably compatible with visual studio: Find the contents of the file piglatinin.txt below:

Program 1 English to Pig Latin Introduction As most of you know, pig Latin is a language game played with English words. It is based on discriminating between vowels and consonants within the word. (Note that a "vowel" is any of the characters "a 'e', 'i', o', or 'u'. A "consonant" is any non-vowel character.) Any English word can be converted to its pig Latin equivalent by using the following algorithm: l) Starting from the first character of the word, locate the position of the first vowel. 2) If there is a consonant (or a string of consonants) to the left of that position, do the following: a) Extract the leading consonant(s) from the word. What remains will begin with a vowel by definition. Let's call that the "residual string." b) Append an "ay" to the end of the consonant string creating a "suffix string c) Append the suffix string to the end of the residual string using a hyphen. 3) If the first letter of the word is a vowel, then append "-way" to the end of the word. For example, let's say we want to convert the word "cabin" to pig Latin. Following the above steps, we do the following: 1) We locate the position of the first vowel. This is the 'a' that occurs at index 1 in the string (i.e., it is the second letter in the string). 2) Since there is a leading consonant in this case, "c', it is removed from the word creating the residual string abin a) We take the consonant, c', append an "ay" to it, creating the suffix string cay b) We append that to the end of the residual string using a hyphen.

Explanation / Answer

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

#define MAX_SIZE 100

char* convertToPigLatin(char* engStr,char* pigLatinStr) {
   unsigned int i=0,j=0,k=0;
   unsigned int str_len = strlen(engStr);

   for(i=0;i<str_len;i++) {
       if (engStr[i] == 'a' || engStr[i] == 'e' || engStr[i] == 'i' || engStr[i] == 'o' || engStr[i] == 'u') {

           if (i > 0) {
               //make a pig latin string and break out of loop
               for(j=0,k=i;k<str_len;k++,j++)
                   pigLatinStr[j] = engStr[k];

               pigLatinStr[j++] = '-';
               pigLatinStr[j] = '';

               engStr[i++] = 'a';
               engStr[i++] = 'y';
               engStr[i] = '';

               strcat(pigLatinStr,engStr);

           } else {
               engStr[str_len++] = '-';
               engStr[str_len++] = 'w';
               engStr[str_len++] = 'a';
               engStr[str_len++] = 'y';
               engStr[str_len++] = '';
               strcpy(pigLatinStr,engStr);

           }  
           break;
       }
   }
   return pigLatinStr;
}

int main() {
   char str[MAX_SIZE];
   char* new_str=NULL;
   FILE* fp1;
   FILE* fp2;

   fp1 = fopen ("pigLatinIn.txt","r");
   fp2 = fopen ("pigLatinOut.txt","w");

   if (fp1 == NULL || fp2 == NULL) {
       (fp1== NULL?perror(fp1):perror(fp2));
       return -1;
   }

   fprintf(fp2,"English Word Latin Word ");
   fprintf(fp2,"---------------- --------------- ");
   while (!feof(fp1)) {
       fscanf(fp1,"%s",str);

       new_str = (char*) malloc(strlen(str)+5);

       if (NULL == new_str) {
           printf(" Memory allocation failure...");
           return -1;
       }
       fprintf(fp2,"%s ",str);
       new_str = convertToPigLatin(str,new_str);

       fprintf(fp2,"%s ",new_str);

       free(new_str);
   }
   fclose(fp1);
   fclose(fp2);
}

Following is the snapshot of output.

English Word               Latin Word
----------------               ---------------
go                   o-gay
placidly                   acidly-play
amid                   amid-way
the                   e-thay
noise                   oise-nay
and                   and-way
haste                   aste-hay
and                   and-way
remember                   emember-ray
what                   at-whay
peace                   eace-pay
there                   ere-thay
may                   ay-may
be                   e-bay
in                   in-way
silence                   ilence-say
as                   as-way
far                   ar-fay
as                   as-way
possible                   ossible-pay
without                   ithout-way
surrender                   urrender-say
be                   e-bay
on                   on-way
good                   ood-gay
terms                   erms-tay
with                   ith-way
all                   all-way
persons                   ersons-pay
speak                   eak-spay
your                   our-yay
truth                   uth-tray
quietly                   uietly-qay
and                   and-way
clearly                   early-clay
and                   and-way
listen                   isten-lay
to                   o-tay
others                   others-way
even                   even-way
the                   e-thay
dull                   ull-day
and                   and-way
the                   e-thay
ignorant                   ignorant-way
they                   ey-thay
too                   oo-tay
have                   ave-hay
their                   eir-thay
story                   ory-stay
if                   if-way
you                   ou-yay
compare                   ompare-cay
yourself                   ourself-yay
with                   ith-way
others                   others-way
you                   ou-yay
may                   ay-may
become                   ecome-bay
vain                   ain-vay
or                   or-way
bitter                   itter-bay
for                   or-fay
always                   always-way
there                   ere-thay
will                   ill-way
be                   e-bay
greater                   eater-gray
and                   and-way
lesser                   esser-lay
persons                   ersons-pay
than                   an-thay
yourself                   ourself-yay
enjoy                   enjoy-way
your                   our-yay
achievements                   achievements-way
as                   as-way
well                   ell-way
as                   as-way
your                   our-yay
plans                   ans-play
be                   e-bay
yourself                   ourself-yay
especially                   especially-way
do                   o-day
not                   ot-nay
feign                   eign-fay
affection                   affection-way
beyond                   eyond-bay
a                   a-way
wholesome                   olesome-whay
discipline                   iscipline-day
be                   e-bay
gentle                   entle-gay
with                   ith-way
yourself                   ourself-yay
you                   ou-yay
are                   are-way
a                   a-way
child                   ild-chay
of                   of-way
the                   e-thay
universe                   universe-way
no                   o-nay
less                   ess-lay
than                   an-thay
the                   e-thay
trees                   ees-tray
and                   and-way
the                   e-thay
stars                   ars-stay
you                   ou-yay
have                   ave-hay
a                   a-way
right                   ight-ray
to                   o-tay
be                   e-bay
here                   ere-hay
and                   and-way
whether                   ether-whay
or                   or-way
not                   ot-nay
it                   it-way
is                   is-way
clear                   ear-clay
to                   o-tay
you                   ou-yay
no                   o-nay
doubt                   oubt-day
the                   e-thay
universe                   universe-way
is                   is-way
unfolding                   unfolding-way
as                   as-way
it                   it-way
should                   ould-shay
be                   e-bay
cheerful                   eerful-chay
strive                   ive-stray
to                   o-tay
be                   e-bay
happy                   appy-hay