Create a program that will ask a string from the user, your program should automatically exchange the 1st & the last letter of every word in the string
Exchange 1st & last letter in string
Collapse
X
-
have you read this
and do you have a question? -
One way of doing this is to initialize a string with a sentence and allocate pointers to the 1st and last letters of the first word.
Code:string s ="When will you be back"; *p1=&s[0]; *p2=&s[3]; swap(p1,p2) // prints ' nheW'
p2+=2; //points to the 1st letter in next word
p1=p2; // p1 does the same and is where you want it
Then advance p2 to the last letter in 2nd word by:
while(p2>='a' && p2<='z') p2++;//it will go too far (to the space) so p2- - outside the while loop.
now swap(*p1,*p2);Comment
Comment