view ReUariBw @ 7616:c6066f594ab5

<Kaynato> mv dao bin/dao
author HackBot
date Fri, 29 Apr 2016 01:03:33 +0000
parents e507c8c14fbd
children
line wrap: on
line source

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;
}