解答例10-5

【問1】

(解答例1)

#include <stdio.h>

int main( void )
{
	char *name[7] = {
		"Iizumi", "Kanto", "Kudo", "Sato", 
		"Sugawara", "Matuda", "Wada"
	};
	char **p;
	int i, j;

	p = name;
	for ( i = 0; i < 7; i++ ){
		for ( j = 0; *( *( p+i ) + j ) != '\0'; j++ );
		printf( "%2d : %s\n", j, *( p+i ) );
	}

	return 0;
}

(解答例2)

#include <stdio.h>

int main( void )
{
	char *name[7] = {
		"Iizumi", "Kanto", "Kudo", "Sato", 
		"Sugawara", "Matuda", "Wada"
	};
	char **p;
	int i, j;

	p = name;
	for ( i = 0; i < 7; i++ ){
		for ( j = 0; *( *p+j ) != '\0'; j++ );
		printf( "%2d : %s\n", j, *p );
		++p;
	}
	return 0;
}

(解答例3)

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

int main( void )
{
	char *name[7] = {
		"Iizumi", "Kanto", "Kudo", "Sato", 
		"Sugawara", "Matuda", "Wada"
	};
	char **p;
	int i;

	p = name;
	for ( i = 0; i < 7; i++ ) {
		printf( "%2d : %s\n", strlen( *p ), *p );
		++p;
	}

	return 0;
}

戻る


banner初心者のためのポイント学習C言語」
Copyright(c) 2000-2004 TOMOJI All Rights Reserved