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;
}

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() ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.