実践研修

今日はこんなプログラム。
/*文字配列より、入力文字が何バイト目にあるか調べるプログラム*/
/*プログラム作成者:*/

#include
#include

main(){
int chp( char *pt, char word );
int n;
char *pt;
char wordlen[] = "ABCDEFGHIJKLMN";
char word;

pt = wordlen;

printf( "'A'~'N'で検索したい文字を入力して下さい。\n" );
printf( "検索文字==>" );
scanf( "%c", &word );

n = chp( pt, word );

if( n == -1 ){
printf( "入力された文字%cは文字列の中にはありませんでした。\n", word );
}
else{
printf( "検索文字%cは文字列の%dバイト目にあります。\n", word, n );
}
}

int
chp( char *pt, char word ){
char *p;
int count;

count = 1;

for( p = pt; *p != '\0'; p++, count++ ){
if( *p == word ){
return count;
}
}
return -1;
}