0

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 by Narue: added code tags

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by vijayan121
0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.