piglatin.c revision d29b2c4438482eb00488be49a1f5d6835f455546
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc.
* All rights reserved.
* Use is subject to license terms.
*
* Very crude pig latin converter.
* Piglatin is an encoded form of English that is often used by children
* as a game. A piglatin word is formed from an English word by:
*
* . If the word begins with a consonant, move the consonant to the end of
* the word and append the letters "ay". Example: "door" becomes "oorday".
*
* . If the word begins with a vowel, merely append "way" to the word.
* Example: "ate" becomes "ateway
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <strings.h>
#include <ctype.h>
int
main()
{
*sb = '\0';
char c = (char)ic;
/*
* Ignore all possible formatting statements.
*/
if (c == '%')
ignore = 1;
/*
* Isolate the word that will be converted.
*/
((c != '%') && (c != '.') && (c != '#') && (c != '-'))))) {
char s = buffer[0];
/*
* If we haven't collected any words yet simply
* printf the last character.
*/
if (word == 0) {
continue;
}
/*
* Leave format strings alone - contain "%".
* Leave single characters alone, typically
* these result from "\n", "\t" etc.
*/
if ((s == 'a') || (s == 'A') ||
(s == 'e') || (s == 'E') ||
(s == 'i') || (s == 'I') ||
(s == 'o') || (s == 'O') ||
(s == 'u') || (s == 'U')) {
/*
* Append "way" to the word.
*/
} else {
/*
* Move first letter to the end
* of the word and add "ay".
*/
sb++;
*cb = s;
}
} else
*cb = '\0';
/*
* Output the collected buffer, the last character
* read and reinitialize pointers for next round.
*/
continue;
}
/*
* Store this character into the word buffer.
*/
*cb++ = c;
*cb = '\0';
word = 1;
}
return (0);
}