subject

Write a program that inputs a c-string from the user and then reverses the contents of the string. your program should work by using two pointers. the "head" pointer should be set to the address of the first character in the string, and the "tail" pointer should be set to the address of the last character in the string (i. e. the character before the terminating null). the program should swap the characters referenced by these pointers, increment "head" to point to the next character, decrement "tail" to point to the second to last character, and so on, until all characters have been swapped and the entire string reversed.

template:

#include
#include
#include
int main()
{
char mystr[80];
char temp;
char *head = null, *tail = null;
std: : cout < < "enter a string less than 80 characters long." < < std: : endl;
cin. getline(mystr,80);
/* assign mystr to both head and tail. be cognizant to the position of each, especially tail in order to avoid pointing to the \0 portion of the string. */
// *** your code here ***
/* write a while loop to reverse the string */
while (// *** your code here ***)
{
// *** your code here ***
} // end while
std: : cout < < "your string reversed is : " < < mystr < < std: : endl;
return 0;
} // end main

tips:
1. use strlen to calculate the address of the last character in the string. loop until head > = tail. use cin. getline to input a c-string.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:30
How do you take a green screen out of the video while editing?
Answers: 2
question
Computers and Technology, 24.06.2019 13:30
Consider jasper’s balance sheet. which shows how to calculate jasper’s net worth?
Answers: 1
question
Computers and Technology, 24.06.2019 17:30
Which computer network component connects two different networks together and allows them to communicate? a is a node (or a device) that connects two different networks together and allows them to communicate.
Answers: 2
question
Computers and Technology, 25.06.2019 00:30
Which email writing etiquette should ariel follow to let people know that she received their message? a. reply to their messages immediately b. use formal language c. specify the email's intent in the subject field d. be direct when writing the reply
Answers: 1
You know the right answer?
Write a program that inputs a c-string from the user and then reverses the contents of the string. y...
Questions
question
Mathematics, 24.07.2020 14:01
question
Biology, 24.07.2020 14:01
question
Mathematics, 24.07.2020 14:01
Questions on the website: 13722363