Thread: palindromes....

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    palindromes....

    Palindromes are words or phrases that read the same backwards as forwards....

    as I notice on the previous forums, some effort has been expended on this topic..

    and I have some questions, which (I believe) would simplify everything.

    it has to do with the source code below...(it is working)..
    but what i can't discern is another function or tool that i may use
    to store the "backwards string"..

    in other words... I want to store the string that was read backwards on some char array, lets say "tmp"...
    then later on I may compare it if it is a palindrome or not...


    here it goes:

    Code:
    #include<stdio.h>
    #include<string.h>
    
    main()
    {
    
     char str[80];
     int i;
    
     clrscr();
    
     printf("enter string: ");
     gets(str);
    
     for(i=strlen(str)-1; i>=0; i--)
    
     printf("%c", str[i]);
    
     getch();
    }
    ------

    notice that each true statement in the for loop prints a character backwards...

    but what I really want is to store all those characters(now backwards),......
    and then "printf" them all at once ... [not one by one]..

    Any ideas or codes to share ?? I'll take note of it !!

    Thank You !!

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    why not gets() ??

    any reason why I can't use gets() ?

    are there some disadvantages...? (either on this program's purpose, or anywhere else??)

    anyway, Thanks Dude for your comment and codes...
    I'll have it scratched on my notes !!

    Thanks !!

  3. #3
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314

    Re: why not gets() ??

    Originally posted by imbecile in C
    any reason why I can't use gets() ?
    Well, Salem gave you the link to the gets() FAQ entry. If you read that you will discover gets() to be the mother of all evil... ehm.. almost

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    MY GOD!

    To quote Salem,
    First thing - don't use gets()
    FAQ
    Is there ANY chance you clicked that link? Just because it says "FAQ" doesn't mean you're stupid if you click it. Click it already. It has the exact answers to what you just said. Here's the link a few more times, increasing the chances you'll click it accidentally.

    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    FAQ
    Away.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    Why gets() is bad ..........

    Stupid is as Stupid does, Sir



    ***
    imbecile in C (as with everything else)





    p.s: Thanks ! I gotta pee.....

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    you do realize there is a strrev function in string.h right??

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >you do realize there is a strrev function in string.h right??

    You do realize that strrev is non-standard, right?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    strrev !!!

    ""you do realize there is a strrev function in string.h right??""

    ooppss... not in my reference here,.. perhaps in the library or somewhere on the net..

    I'll find it anyway !!

    thanks dudes !!

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>not in my reference here,
    >>I'll find it anyway !!
    It seems you over looked another poster: Dave_Sinkula pointed out the strrev is non-standard, meaning it isn't guaranteed to be in any library. If you want to use it, I suggest you write your own and call it Strrev(), that way your code should compile OK on any decent C compiler.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Palindromes
    By jewelz in forum C++ Programming
    Replies: 57
    Last Post: 02-23-2009, 06:11 PM
  2. Palindromes and Bitwise operators
    By Dr Tornillo in forum C Programming
    Replies: 8
    Last Post: 08-02-2007, 02:31 PM
  3. palindromes and bool
    By justinc911 in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2003, 07:58 PM
  4. Palindromes
    By cman in forum C Programming
    Replies: 1
    Last Post: 05-05-2003, 06:39 AM
  5. strings and palindrome's
    By watshamacalit in forum C Programming
    Replies: 6
    Last Post: 01-07-2003, 06:17 PM