fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define BUFFERLEN 100
  5.  
  6. int compareStrings(const char*, const char*);
  7.  
  8. int main(void) {
  9. const char * str1 = "end of story";
  10. char buffer[BUFFERLEN] = {0};
  11.  
  12.  
  13. while(1)
  14. {
  15. fgets(buffer, BUFFERLEN-1, stdin );
  16. if( compareStrings(str1, buffer) == 1)
  17. {
  18. printf("end of story! exiting...");
  19. break;
  20. }
  21. printf("entered %s\r\n", buffer);
  22. }
  23.  
  24. return 0;
  25. }
  26.  
  27. int compareStrings(const char * first, const char * second)
  28. {
  29. int len1 = strlen(first);
  30. int len2 = strlen(second);
  31.  
  32.  
  33. if(len1 != len2)
  34. {
  35. return 0;
  36. }
  37. int i = 0;
  38. for (; i < len1; ++i)
  39. {
  40. if(first[i] != second[i])
  41. {
  42. return 0;
  43. }
  44. }
  45. return 1;
  46. }
Success #stdin #stdout 0s 2160KB
stdin
asd
tetst
asda asdasd
xxyyzz
end of story
stdout
entered asd

entered tetst

entered asda asdasd

entered xxyyzz

end of story! exiting...