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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:00, ahmedislife
Alocal reaction will occur at the site of the exposure such as irritation or damage to the skin eye or local reaction will occur at the site of the exposure such as irritation or damage to the skin ireland lounges
Answers: 3
image
Computers and Technology, 22.06.2019 16:20, mandy9386
Consider the following statements, then select one of the answers below: the signal() function shown below registers "sig_handler()" as the signal handler function for the sigkill signal, without the complexity of using when the sigkill signal is sent to a process running this code, by a user typing "kill -kill ", where the correct process id is used for to target the process, sig_handler() will be executed.
Answers: 1
image
Computers and Technology, 22.06.2019 21:30, aesthetickait
How do you take a green screen out of the video while editing?
Answers: 2
image
Computers and Technology, 22.06.2019 22:10, Metlife
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
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 in other subjects:

Konu
Mathematics, 11.01.2021 21:20
Konu
Mathematics, 11.01.2021 21:20