/* * DOS Pig Latin Filter * Refer to Lesson 12-5 for more information on * filters. This program uses the standard type * of filter as introduced for the ROT13.C * program */ #include #include void iglatinpay(char *english); void main() { char word[32]; //input storage char *w; //pointer to the word buffer char ch; int count; /* * This is a standard construction for filters: * fgetchar reads STDIN and fputchar writes STDOUT * * Along the way, the isalpha() function is used to * find the start of a word. If so, a while loop * is set up to read that word and store it into * the word[] buffer. The word is only read at this * point, not displayed. * * When the end of the word is found, it is capped * with a NULL byte and sent to the iglatinpay() * function to be turned into Pig Latin. It's that * word that is then send to STDOUT */ do { ch = fgetchar(); if(isalpha(ch)) //a word starts { count=0; while(isalpha(ch)) //read the word { word[count] = ch; //store it count++; ch = fgetchar(); //keep reading } word[count] = '\0'; //cap with a NULL iglatinpay(word); //process the word /* This routine displays the word stored in word[] */ w = word; while(*w) { fputchar(*w); //use STDOUT w++; } /* Finally, he original non-alpha character is displayed */ fputchar(ch); } else //the else part { // handles non-alpha fputchar(ch); // I/O } } while(ch!=EOF); }