#include <stdio.h>
#include <string.h>
int main( void )
{
char a[20], b[20];
int len;
strcpy( a, "abcde" );
strcpy( b, "vwxyz" );
printf( "文字列a = %s\n文字列b = %s\n", a, b );
if ( strcmp( a, b ) == 0 ) {
printf( "文字a,bは等しい\n" );
}
else if ( strcmp( a, b ) > 0 ) {
printf( "文字aはbより大\n" );
}
else {
printf( "文字aはbより小\n" );
}
strcat( a, b );
len = strlen( a );
printf( "文字列a = %s\n", a );
printf( "文字列aの長さ = %d\n", len );
return 0;
}
#include <stdio.h>
#include <string.h>
#define LEN 100 /*(注)#defineについては第18章を参照してください */
int main( void )
{
char str_a[LEN+1] = ""; /* 文字列先頭に NUL設定 */
char str_b[LEN+1] = "";
while( strlen( str_b ) < 100 ) {
printf( "文字列を入力してください" );
scanf( "%s", str_a );
strncat( str_b, str_a, LEN - strlen( str_b ) );
printf( "\nstr = %s\n", str_b );
}
printf( "len = %d\n", strlen( str_b ) );
return 0;
}
▼戻る▼
「初心者のためのポイント学習C言語」 Copyright(c) 2000-2004 TOMOJI All Rights Reserved