Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char *s1 = "ABCD";
- char *s2 = "ABC123";
- int ret;
- printf( "%s と %s の 3文字目までの比較¥n", s1, s2 );
- ret = strncmp( s1, s2, 3 );
- if( ret == 0 ){
- printf( "文字列が一致しました¥n" );
- }
- else{
- printf( "文字列が異なります¥n" );
- }
- printf( "%s と %s の 5文字目までの比較¥n", s1, s2 );
- ret = strncmp( s1, s2, 5 );
- if( ret == 0 ){
- printf( "文字列が一致しました¥n" );
- }
- else{
- printf( "文字列が異なります¥n" );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment