#include <stdio.h>
/*
5.文字列を引数としてその文字列の長さを返す関数mystlen()を作成せよ。
*/
int mystlen(const char* s)
{
int n = 0;
while (*s != '\0') n++, s++;
return n;
}
/*
6.外部変数を利用して自分が呼ばれた回数を数えて返す関数times()を作成せよ。
*/
int times_counter = 0;
int times(void)
{
return ++times_counter;
}
/*
7.問題6の外部変数の変わりに静的なローカル変数を利用して同様のプログラムを作成せよ。
*/
int times_static(void)
{
static int times_counter = 0;
return ++times_counter;
}
int main(void)
{
const char* str = "qwerty";
int str_len;
int i;
printf("%s is %d length\n", str, mystlen(str));
for (i=0; i<30; i++){
if (i % 2 == 0) printf("step%2d ver.6 called %d\n", i, times());
if (i % 3 == 0) printf("step%2d ver.7 called %d\n", i, times_static());
}
return 0;
}