Thread: confused on strncmp vs memcmp

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    79

    confused on strncmp vs memcmp

    I have two arrays defined as char a[4], b[4]....neither will (or should not) contain a null character.

    Can someone tell me is it better to use memcmp or strncmp when comparing the two? or for that matter do both work?

    Thanks

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    810
    Use memcmp() for possible non Nul ('\0') terminated arrays. Use strcmp() for Nul terminated "Strings"

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    79
    Perfect

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memcmp ?
    By ridgerunnersjw in forum C Programming
    Replies: 6
    Last Post: 01-08-2021, 12:47 PM
  2. !memcmp in set
    By thames in forum C Programming
    Replies: 2
    Last Post: 01-13-2013, 12:55 PM
  3. Where is the defination of memcmp?
    By shwetha_siddu in forum C Programming
    Replies: 3
    Last Post: 03-25-2009, 06:47 AM
  4. Access Violation using memcmp?
    By someprogr in forum C Programming
    Replies: 3
    Last Post: 12-31-2007, 01:45 AM
  5. Question about using memcmp ()
    By Vortex in forum C++ Programming
    Replies: 5
    Last Post: 06-03-2006, 03:44 PM

Tags for this Thread