fork download
  1. #include <stdio.h>
  2.  
  3. int myStrcmp(char s[], char t[])
  4. {
  5. int i = 0;
  6. while (s[i] != '\0' && t[i] != '\0') {
  7. if (s[i] != t[i]) {
  8. return 0; // 違う文字があれば 0
  9. }
  10. i++;
  11. }
  12. // どちらも終端に到達していれば同じ文字列
  13. if (s[i] == '\0' && t[i] == '\0') {
  14. return 1; // 完全一致
  15. } else {
  16. return 0; // 片方が途中で終わった場合は不一致
  17. }
  18. }
  19.  
  20. int main() {
  21. int ans;
  22. char s[100];
  23. char t[100];
  24. scanf("%s %s", s, t);
  25. ans = myStrcmp(s, t);
  26. printf("%s = %s -> %d\n", s, t, ans);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5320KB
stdin
abcd
abcd
stdout
abcd = abcd -> 1