Thread: is it possible to compare a string with return?

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    22

    is it possible to compare a string with return?

    by using strcmp i think it's not working
    Code:
    strcmp(input,"\n");
    can anyone help?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    With that amount of code - no.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Have you actually looked up strcmp and see how it is used and what the function prototype looks like or did you just ASSUME you know how to use it.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by vince3214 View Post
    by using strcmp i think it's not working
    Code:
    strcmp(input,"\n");
    can anyone help?
    Well very unclear with that much code. But assuming the input has some string, yes the strcmp will compare both input and "\n". Of course you wouldn't the results as expected if the compare fails. You need to show us more.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    22
    well assume input is a string and compare with "\n"
    if my input is return(enter), is it gonna return 0?

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Depends on what function you are using to get keyboard input. Some may strip off the "\n".

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by vince3214 View Post
    well assume input is a string and compare with "\n"
    if my input is return(enter), is it gonna return 0?
    Tell you what Vince... post more than half a line of code for us to look at...

    It's obvious you are trying to solve some kind of problem but you won't get much help with it unless we can actualy see it.

    And, darn, wouldn't you know it... my mind reading ray gun is in the shop for adjustment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unable to compare string with 'getter' returned string.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2009, 05:56 PM
  2. Compare 2 String
    By nitediver in forum C Programming
    Replies: 2
    Last Post: 10-06-2009, 07:48 AM
  3. Replies: 6
    Last Post: 04-09-2006, 04:32 PM
  4. string compare
    By IceBall in forum C Programming
    Replies: 4
    Last Post: 10-12-2003, 05:26 PM
  5. need help on string compare
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 06-07-2002, 08:55 PM