All I need help with is to change the last part to a user prompt instead of just already having the value entered within the program. The part I need to change is bold. This program is supposed to reverse the word order. i.e apples and oranges = oranges and apples.
Can someone write it please?
I was thinking something like:
printf("Enter phrase> ");
scanf("this is where i'm lost to scan multiple words");
printf("here too");
Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
void reverse (char *s, int len)
{
int i, j;
for (i = 0, j = len - 1; i < j; i++, j--) {
char save = s[i];
s[i] = s[j];
s[j] = save;
}
}
void revword (char *s)
{
while (*s != '\0') {
char *e = s;
/* Find the end of a word */
while (*e != '\0' && !isspace (*e))
e++;
reverse (s, e - s);
/* Find the next word */
s = e;
while (*s != '\0' && isspace (*s))
s++;
}
}
int main (void)
{
char s[] = ("apples and oranges");
reverse (s, strlen (s));
revword (s);
puts (s);
getch();
return 0;
}