This is not giving right output :(((

#include<iostream.h>
#include<conio.h>
using namespace std;
int main()  
{  
      
    char c[80],d[80];  
    cout<<"Enter a string = ";  
    cin.get(c,80);  
    strcpy(c,d);  
    strrev(d);  
         cout<<"String = "<<c;  
  
         cout<<"Reverse word "<<d;  
    getch();  
    return 0;
}

Edited 5 Years Ago by Narue: added code tags

Its because strcpy works like this strcpy(<destination>,<source>) you reversed the destination with source that's why it didn't work.

Without using arrays and without using strings? That makes it interesting.
Something like a linked list would obviously work, but perhaps storing each character in the local frame of a (recursive) function would be the simplest.

#include <iostream>

void read_and_print_reverse()
{
    char c = std::cin.get() ;
    if( c != '\n' )
    {
        read_and_print_reverse() ;
        std::cout << c ;
    }
}

int main()
{
    std::cout << "enter a sentence (terminate it with a new-line): " ;
    read_and_print_reverse() ;
}
This question has already been answered. Start a new discussion instead.