第一次在本站发帖。我正在尝试编写一个猪拉丁语翻译程序,并且很难删除字符串中每个单词的第一个字符并将其附加到单词的末尾。如果有人能给我任何建议,将不胜感激。但是我试图不改变我已经拥有的太多。就字符串函数而言,我仅限于使用 strcpy、strcmp、strlen 和 strtok,因为我只是一个在综合课程中被难倒的学生。
#include <stdio.h>
#include <string.h>
void main (void)
{
char sentence[81]; /* holds input string */
char *platin; /* will point to each word */
printf ("This program translate the words in your sentence.\n");
printf ("Type end to finish.\n");
do /* for each sentence */
{
printf ("\n\nType a sentence until 'stop': \n ");
gets (sentence);
platin = strtok (sentence, " ");
while (platin != NULL) /*Moves translator from word to word */
{
if (strchr("aeiouAEIOU", *platin)) /*Checks for vowels */
{
printf(" %sway ", platin);
}
else if (strchr("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ",*platin))
{
printf(" %say", platin);
}
platin = strtok(NULL, " ");
}
} while (strcmp(sentence, "stop") != 0 );
}