piglatin.c (730B)
1 /* Exercise 8.13 */ 2 3 #include <stdio.h> 4 #include <string.h> 5 6 #define SIZE 30 7 8 void printLatinWord(char *p); 9 10 int main(void) { 11 char english[SIZE] = "jump the computer"; 12 char *tokp; 13 14 printf("The english string is:\t\t%s\n", english); 15 printf("The pig lating string is:\t"); 16 17 tokp = strtok(english, " "); 18 while( tokp != NULL ) { 19 printLatinWord(tokp); 20 tokp = strtok(NULL, " "); 21 } 22 23 printf("\n"); 24 25 return 0; 26 } 27 28 /* Take an english word and write it in Pig Latin */ 29 void printLatinWord(char *p) 30 { 31 char string[20]; 32 33 strcpy(string, ++p); 34 35 string[strlen(string) + 1] = '\0'; 36 string[strlen(string)] = *(--p); 37 38 strcat(string, "ay"); 39 40 printf("%s ", string); 41 } /* eof printLatinWord() */ 42