How to check if string start with "LOGIN" in C

1 Answer

0 votes
#include <stdio.h> 
#include <string.h>

int main(void)
{   
    char str[] = "LOGIN: email : password";
    
    // int memcmp(const void *str1, const void *str2, size_t n)
    int result = memcmp(str, "LOGIN", 5);
 
    if (result == 0) {
        puts("yes");
    } else {
        puts("no");
    }

    return 0;
}
 
 
         
/*
run:
      
yes
     
*/

 



answered Jul 4, 2024 by avibootz
...