hello i need help

Write a program that accepts a C-string input from the user and 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.

Hint: Two pointers should be declared without initialization
Hint: Pointer head points to the first character of C-string ==> head = & C-string[0] ;
Hint: To get the number of characters in a C-string ==> strlen(C-string)
Hint: for statement must use both head and tail pointers as count variables, so the loop condition should be ==> head <= tail
Hint: Swap values of two char variables a and b (with char T) ==> T = a; a = b; b = T;
* variable a and b should be replaced with your variable names
Hint: Don’t forget to display C-string after swapping

Sample Output:

Please enter a character string: hello

CString = "olleh"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main()
{
	char word[30];
	char* head, *tail;


	printf("Please enter a character string: ");
	scanf("%s",&word);
	head=&word[0];
	tail=strchr(word,'\0')-1;

	for (head, tail; head <= tail; head++, tail--)
	{
		char tmp;
		tmp=*head;
		*head=*tail;
		*tail=tmp;
	}

	printf("\nC-String = %s\n",word);

	system("PAUSE");

	return 0;
}
Topic archived. No new replies allowed.