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 01:00
What is added to the < meta > tag to describe the encoding type?
Answers: 2
question
Computers and Technology, 22.06.2019 07:30
Jasper and samantha are in a robotics competition. the guidelines state that the robots should be able to move a 10-gram weight at least 2 meters and turn in a circle. jasper and samantha have already built the robot. which step of the design process should they follow next to decide whether their robot meets the minimum criteria for the competition?
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Barbara is interested in pursuing a career in the science and math pathway. which qualifications will her reach that goal? a.an advanced knowledge of physics and math b.an advanced knowledge of engineering and math c. an advanced knowledge of physics and robotics an d. advanced knowledge of machinery and math
Answers: 2
question
Computers and Technology, 25.06.2019 05:30
You are asked to calculate an object's velocity, in order to do so you must know the object's a. direction and speed. b. distance and time. c. speed and distance. d. direction and distance.
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
Spanish, 05.05.2020 15:00
question
Mathematics, 05.05.2020 15:00
question
Social Studies, 05.05.2020 15:00
question
Mathematics, 05.05.2020 15:00