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, 21.06.2019 18:00
What ordering of tcp flags makes up the three-way handshake?
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
How do you write an argumentative essay about the importance of free enterprise ?
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
List 3 items that were on kens resume that should have been excluded
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
What are two ways to access the options for scaling and page orientation? click the home tab, then click alignment, or click the file tab. click the file tab, then click print, or click the page layout tab. click the page layout tab, or click the review tab. click the review tab, or click the home tab?
Answers: 2
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
Questions on the website: 13722359