-5

I'm trying to reverse a string using pointers which is I guess a pretty standard program.

I tried doing this using a single pointer unlike other methods I've seen where people use two pointers for beginning and end.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
 clrscr();
 char x[15];
 cout<<"enter word";
 gets(x);
 int l=strlen(x);
 char* p;
 p=x[15];
 for(int i=l-1;i>=0;i++)
 {
  p*=x[i];
  p--;
 }
 puts(x);
 getch();
}

I expected it to work but it shows a single error that it can't convert char* to char. I'm pretty new to pointers but I thought pointers are just aliases for the memory locations so what's the problem? Or am I missing something fundamental?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Sameer Thakur
  • 101
  • 1
  • 3

1 Answers1

3

Put the asterisks before the p to dereference it.

*p=x[i];

Also, when you assign p = x[15], you're dereferencing x (which makes it a char) and assigning it to p (which is a char*).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
avenmia
  • 2,015
  • 4
  • 25
  • 49