Thread: strncmp

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    10

    strncmp

    HI guy's a small problem here with a strncmp

    Don;t know what's wrong but this doesn;t seem to work as i expect.

    when the strings are the same it should print something and when the strings aren't the same it should continue after this code...

    Code:
     
    do
    {
    	printf("%s",arra[f]);
    	printf("%s",identificatie);
    	Sleep(1000);
    	if (strncmp (identificatie, arra[f], 3) == 1)	//compare  array with the string in identification
    	{
    	printf("\n\n\n\n%s\n\n\n",msg18);	// They are the same
    	system("Pause");
    	f=9;
    	}
    	else
    	f++;
    
    								
    }while (f<=6);


    When i run it it gives me nicely the array with the values and the value in identification, but when they are the same it just continues withouth the msg and when they aren't the same it just continues as well...

    TIA Fred
    Last edited by TL62; 01-16-2008 at 04:01 AM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    10

    return value

    Quote Originally Posted by vart View Post
    Did that:-) just noticed i made mistake in the code i posted here, the return value is in the original code set to ==0, but still not working

    Tia

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    so printf also th ereturn value of strncmp
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Not working how?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > i made mistake in the code i posted here, the return value is in the original code set to ==0
    So in other words, we have no confidence in the code we're looking at has absolutely anything to do with the code you're trying to run.

    So it really doesn't matter what we suggest, because it could be down to some other mistake you haven't posted.

    In other words, we're all wasting our time.

    Post your ACTUAL CODE, not some half-assed approximation snipped for brevity crap.

    http://www.catb.org/~esr/faqs/smart-questions.html
    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.

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    10
    Quote Originally Posted by Salem View Post
    > i made mistake in the code i posted here, the return value is in the original code set to ==0
    So in other words, we have no confidence in the code we're looking at has absolutely anything to do with the code you're trying to run.

    So it really doesn't matter what we suggest, because it could be down to some other mistake you haven't posted.

    In other words, we're all wasting our time.

    Post your ACTUAL CODE, not some half-assed approximation snipped for brevity crap.

    http://www.catb.org/~esr/faqs/smart-questions.html
    Sheesh, how politefull of you, like no one ever makes a mistake... but no need for you to help anyone, seems you don;t even know how to behave so probably you have no other skills as well

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    10

    Solved it

    Thx for sending me in the right direction, i found it....

    Thx for helping me out

  9. #9
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by TL62 View Post
    Sheesh, how politefull of you, like no one ever makes a mistake... but no need for you to help anyone, seems you don;t even know how to behave so probably you have no other skills as well
    Granted, it is stupid to assume that one's post count on a forum is directly proportional to one's ability to work with the forum's subject, however, as you can see, this forum is full of elitists and megalomaniacs - Don't you think Salem over there would've been flamed off of the boards before he got 18 thousand posts if he had no clue what he was talking about?

    He's perfectly right.

    You say the code is different from what you've posted. What he meant by what he said was that you might have inadvertently modified some other part of the code than the if statement too, thus possibly making another mistake which does not exist in the code you posted - Thus making it impossible for us to point it out.

    By the way - those who asks for help are supposed to be humble. Bend over and take it like a man.

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    10

    I am...

    Quote Originally Posted by IceDane View Post
    Granted, it is stupid to assume that one's post count on a forum is directly proportional to one's ability to work with the forum's subject, however, as you can see, this forum is full of elitists and megalomaniacs - Don't you think Salem over there would've been flamed off of the boards before he got 18 thousand posts if he had no clue what he was talking about?

    He's perfectly right.

    You say the code is different from what you've posted. What he meant by what he said was that you might have inadvertently modified some other part of the code than the if statement too, thus possibly making another mistake which does not exist in the code you posted - Thus making it impossible for us to point it out.

    By the way - those who asks for help are supposed to be humble. Bend over and take it like a man.
    I know and i don;t say that he isn;t right but a bit politness for someone who is fairly new here would be nice as well..
    that was what ii was talking about and about his shills i want talking about his programming skills i surely believe he knows a lot about it...
    so if it was taken that way i am sorry...
    I might explain things a bit wrong at time because English isn;t my native language....

    regards Fred

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about strncmp
    By sweetorangepie in forum C Programming
    Replies: 8
    Last Post: 03-24-2008, 01:15 PM
  2. unsure of how to use the functions strcmp and strncmp
    By hellgrammite in forum C Programming
    Replies: 8
    Last Post: 12-06-2007, 01:47 AM
  3. strncmp like function in C#
    By x77 in forum C# Programming
    Replies: 4
    Last Post: 11-18-2007, 06:29 AM
  4. Help with strncmp fxn
    By 3kgt in forum C++ Programming
    Replies: 5
    Last Post: 04-30-2003, 02:40 PM
  5. strncmp()
    By xlordt in forum C Programming
    Replies: 2
    Last Post: 10-23-2002, 01:54 PM