User Tools

Site Tools


c:string.h:strncmp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:string.h:strncmp [2012/07/16 22:41]
127.0.0.1 external edit
c:string.h:strncmp [2024/02/16 01:06] (current)
Line 1: Line 1:
-    int strncmp(const char *str1, const char *str2, size_t n);+====== strncmp ====== 
 + 
 +<code c> 
 +#include <stdlib.h> 
 + 
 +int strncmp(const char *str1, const char *str2, size_t n); 
 +</code> 
 + 
 +The strcmp() function compares the two strings ''s1'' and ''s2''.  It returns an integer less than, equal to, or greater than zero if ''s1'' is found, respectively, to be less than, to match, or be greater than ''s2''. The strncmp() function is similar, except it only compares the first (at most) n characters of ''s1'' and ''s2''. 
 + 
 +=====  strncmp C Sourcecode Example ===== 
 +<code c> 
 +/*  
 + * strncmp example code 
 + * http://code-reference.com/c/string.h/strncmp 
 + */ 
 +#include <stdio.h> 
 +#include <string.h> 
 + 
 +int main( void ) 
 +
 +   const char str1[] = "42 is a bad answer"; 
 +   const char str2[] = "42 is a realy good answer"; 
 +   int i; 
 +  
 +   i = strlen(str1); 
 + 
 +   for(i ; i > 0; i--) { 
 +         if(strncmp( str1, str2, i) == 0) { 
 +               printf("The first %d chars of str1 and str2 are the same\n", i); 
 +        break; 
 +            } 
 +   } 
 + 
 +  return 0; 
 +
 + 
 +
 +</code> 
 + 
 +==== output of strncmp c example ==== 
 +    The first 8 chars of str1 and str2 are the same 

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/strncmp.1342471298.txt · Last modified: 2024/02/16 01:03 (external edit)

Impressum Datenschutz