我一直在 C++ 中遇到此代码的问题:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string words[25];
int i = 0;
char * word;
cout << "Input a phrase, no capital letters please.";
char phrase[100] = "this is a phrase";
word = strtok (phrase, " ,.");
while (word != NULL)
{
i++;
words[i] = word;
cout << words[i] << " ";
word = strtok (NULL, " ,.-");
int g = 0;
}
cout << endl << endl;
int g = 0;
while (g < i)
{
g++;
char f = words[g].at(0);
if ((f == 'a') || (f == 'e') || (f == 'i') || (f == 'o') || (f == 'u') || (f == 'y'))
{
words[g].append("way");
cout << words[g] << " ";
}
else
{
words[g].erase (0,1);
cout << words[g] << f << "ay" << " ";
}
}
cout << endl;
system("PAUSE");
}
我实际上希望我的程序用户生成要放入 char 短语 [100] 的短语,但我无法弄清楚在不搞砸翻译的情况下启动输入的正确语法。
这是一个将短语翻译成猪拉丁语的程序。