d10070dd

strncmp

Oct 28th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6.   char *s1 = "ABCD";
  7.   char *s2 = "ABC123";
  8.   int ret;
  9.  
  10.   printf( "%s と %s の 3文字目までの比較¥n", s1, s2 );
  11.   ret = strncmp( s1, s2, 3 );
  12.   if( ret == 0 ){
  13.     printf( "文字列が一致しました¥n" );
  14.   }
  15.   else{
  16.     printf( "文字列が異なります¥n" );
  17.   }
  18.  
  19.   printf( "%s と %s の 5文字目までの比較¥n", s1, s2 );
  20.   ret = strncmp( s1, s2, 5 );
  21.   if( ret == 0 ){
  22.     printf( "文字列が一致しました¥n" );
  23.   }
  24.   else{
  25.     printf( "文字列が異なります¥n" );
  26.   }
  27.  
  28.   return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment