fork download
  1. #include <stdio.h>
  2.  
  3. int myStrlen(char s[]) {
  4. int count = 0; // 1. 0で初期化する
  5. while (s[count] != '\0') {
  6. count++; // 2. 添字とカウントを同時に進める
  7. }
  8. return count;
  9. }
  10.  
  11. int main() {
  12. int len;
  13. char s[100];
  14. scanf("%99s", s); // バッファオーバーフロー防止のため %99s にするとより安全です
  15. len = myStrlen(s);
  16. printf("%s -> %d\n", s, len);
  17. return 0;
  18. }
Success #stdin #stdout 0s 544KB
stdin
abcd
stdout
abcd -> 4