fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cctype>
  4.  
  5. using std::cin;
  6. using std::cout;
  7. using std::endl;
  8.  
  9. bool equals(const char*, const char*);
  10.  
  11. int main()
  12. {
  13.  
  14. // Tests 1a - 1d: Test the equals() function
  15. cout << "Test 1a: ";
  16. if (equals("catapult", "catapult"))
  17. cout << "correct\n";
  18. else
  19. cout << "incorrect\n";
  20.  
  21. cout << "Test 1b: ";
  22. if (!equals("catapult", "catamaran"))
  23. cout << "correct\n";
  24. else
  25. cout << "incorrect\n";
  26.  
  27. cout << "Test 1c: ";
  28. if (!equals("cat", "catamaran"))
  29. cout << "correct\n";
  30. else
  31. cout << "incorrect\n";
  32.  
  33. cout << "Test 1d: ";
  34. if (!equals("catapult", "cat"))
  35. cout << "correct\n";
  36. else
  37. cout << "incorrect\n";
  38.  
  39. cout << endl;
  40. return 0;
  41. }
  42.  
  43. bool equals (const char* str1, const char* str2)
  44. {
  45. if (strcmp(str1, str2) == 0)
  46. return true;
  47.  
  48. return false;
  49. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Test 1a: correct
Test 1b: correct
Test 1c: correct
Test 1d: correct