Compare some characters of two strings: how to use strncmp : String Compare « String « C / ANSI-C






Compare some characters of two strings: how to use strncmp


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

int main ()
{
  char str[][5] = { "CS115" , "CS334" , "CS445" , "CS335" , "CS889" };
  int n;
  printf ("Looking for a class...\n");
  for (n=0 ; n < 5 ; n++)
    if (strncmp (str[n],"CS33*",1) == 0)
    {
      printf ("found %s\n",str[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.String compare: how to use strncmp
5. Compare two strings: how to use strcmp