Thread: strncmp how to?

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

    strncmp how to?

    Trying to use the following unsuccessfully...This is the argument for an if statement....if 0 do ....Can someone tell me what I may be doing wrong here as I never enter it....*p = "ER_CMD#P?"

    Code:
    (!(strncmp(*p, "ER_CMD", 6)))

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    409
    Quote Originally Posted by ridgerunnersjw View Post
    Trying to use the following unsuccessfully...This is the argument for an if statement....if 0 do ....Can someone tell me what I may be doing wrong here as I never enter it....*p = "ER_CMD#P?"

    Code:
    (!(strncmp(*p, "ER_CMD", 6)))
    You need to post a bit more. This looks suspicious as strcncmp takes two pointers. If p is a char ** it is correct, but then what is p pointing to? It's probably set up incorectly and p needs to be a plain char *.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  3. #3
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    269

    Thumbs up

    what I may be doing wrong here
    *p
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main() {
        
        char *string1 = "test";
    
        if ( !strncmp(string1, "test", strlen(string1)) ) {
            printf("equal.");
        } else {
            printf("unequal!");
        }
    
        return 0;
    }
    C library function - strncmp() - Tutorialspoint
    Last edited by Structure; 06-27-2020 at 10:06 AM.
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strncmp implementation help
    By coder222 in forum C Programming
    Replies: 9
    Last Post: 09-13-2015, 10:36 AM
  2. question about strncmp
    By sweetorangepie in forum C Programming
    Replies: 8
    Last Post: 03-24-2008, 01:15 PM
  3. strncmp
    By TL62 in forum C Programming
    Replies: 9
    Last Post: 01-16-2008, 05:12 PM
  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

Tags for this Thread