I got a program that split up words. Like if I write "My name is ali" The program will write
Word one: My
Word two: name
word three: is
word four: ali
Now I want to add something like
int number;
printf("which word do you want to write? number: \n");
scanf("%d",&number)
Then if user writes "four" it is suppose to write ali
or if they write "two" it is supposed to write 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;
}