palindrome HELP !!!

This is a discussion on palindrome HELP !!! within the C Programming forums, part of the General Programming Boards category; one testicle ? WHere's Govtcheez?...

  1. #16
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    one testicle
    ?

    WHere's Govtcheez?

  2. #17
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Watch out for the boogyman.

  3. #18
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Sweet!

    Code:
    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    
    int palindrome(char string[], int size) 
    { 
    	if (size == 0 || size == 1)		
    		return 1; 
    	else if (toupper(string[0]) != toupper(string[size - 1])) 
    		return 0; 
    	else 
    		return palindrome(&string[1], size - 2); 
    } 
    
     
    int main()
    {
    	char a[30];
    
    	printf("Enter Word: ");
    	fgets(a,30,stdin);
    	a[strlen(a) - 1] = '\0';
    		
    	if( palindrome(a, strlen(a)))
    		printf("Palindrome.");
    
    	return 0;
    }

  4. #19
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Troll_King, from a professional view, Uraldor is right. No need for memory allocation or recursion here. Simple loop, simple solution. strrev by the way is not ANSI standard and not included with all compilers I think.

    You can do this in countless ways, you can probably use a hash-table or store the word in a database, rotate it on-screen with DirectX or send it to any available AIM client. But the solution that is the one that is nearest to the assignment is Uraldors. Simple, elegant and works.

    The solution above is nice, I like it, but for the newbie, a loop is easier to understand.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #20
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Actually someone asked if you can return a string from a function, that's why I used malloc and did so. The answer is yes you can return a string from a function.

    Also from a professional standpoint you know nothing! lol.

  6. #21
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    from a professional standpoint you know nothing
    ok i'll stop this.

  7. #22
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>strrev by the way is not ANSI standard and not included with all compilers I think

    and not allowed in homework assignments.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #23
    Registered User
    Join Date
    Oct 2001
    Posts
    13

    sorted

    alright ppl,ive pretty much solved the problem, thanks for every1's help !

  9. #24
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Thank you Uraldor, NVoigt, Novacain and last (but my no means least) Troll-King.

    As I said, I don't know much C (or ANSI C apparently) - but clearly the impertinence of my input has expanded the discussion and provided more information (certainly for me) than might otherwise have been.

    To Uraldor: the omission of toupper was entirely accidental - as I suspect Troll-King recognised (if you did, thanks for your gracious humour).

    To Novacain: It only ocurred to me some time later that the use of strrev was not allowed for homework assignments.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in Recursive String Palindrome Code
    By clegs in forum C Programming
    Replies: 13
    Last Post: 12-21-2008, 12:36 PM
  2. Is it a Palindrome?
    By xp5 in forum C Programming
    Replies: 3
    Last Post: 09-06-2007, 06:26 AM
  3. bool palindrome definition
    By justinc911 in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2003, 05:50 PM
  4. Palindrome
    By Ginny Morgan in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 05:04 PM
  5. Palindrome Coding trouble
    By TheLoneWolf32 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 07:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21