我有一个可以分割单词的程序。就像我写“我的名字是阿里” 程序会写
Word one: My
Word two: name
word three: is
word four: ali
现在我想添加类似的内容
int number;
printf("which word do you want to write? number: \n");
scanf("%d",&number)
然后,如果用户写“四”,则假设写为ali
或者如果他们写“两个”,则应该写name
。
int delaUppText(char input[], char* pekare[])
{
int i=0, j=0;
char prevLetter=' ';
for(i=0; input[i]!=NULL; i++)
{
if(prevLetter==' '&&input[i]!=' ')
{
pekare[j]=&input[i];
j++;
}
prevLetter=input[i];
}
for(i=0; input[i]!=NULL; i++)
{
if (input[i] == ' ')
{
input[i]=NULL;
}
}
return j;
}
int main()
{
char input[200];
char* pekare[100];
int i, antalPekare;
char answer = 32;
int nummer;
do
{
system("cls");
printf("Enter a string: ");
gets(input);
printf("\n");
antalPekare = delaUppText(input, pekare);
for(i=0;i<antalPekare;i++)
{
printf("Ord %d: %s\n", i+1, pekare[i]);
}
printf("\nWould you like to try again? [Space]/[q]");
answer = getch();
if (answer == 32)
{
system("cls");
}
else if (answer == 'q')
{
break;
}
}while (answer == 32);
return 0;
}
最佳答案
不幸的是编译器不会说英语。
因此,如果您的用户必须输入“four”,则不要指望 scanf("%d",&number)
能够识别单词“four”。它只能识别数字,因此您的用户必须输入“4”,或者您必须解析输入以了解他输入的数字单词。德语输入怎么样?
关于c - 用指针数组写入每个字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36085988/