String compare: how to use strncmp : String Compare « String « C / ANSI-C






String compare: how to use strncmp


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  if(argc!=3) {
    printf("Incorrect number of arguments.");
    exit(1);
  }

  if(!strncmp(argv[1], argv[2], 8))
    printf("The strings are the same.\n");

  return 0;
}

           
       








Related examples in the same category

1.Compare strings: strcmp
2.Testing characters in a string: is digit and is alpha
3.Our own string compare function
4. Compare two strings: how to use strcmp
5. Compare some characters of two strings: how to use strncmp