fork download
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define countof(array) (sizeof(array) / sizeof((array)[0]))
  6.  
  7. // Удаляет пробелы (а главное \r\n и \n) с конца строки.
  8. static void rstrip(char *s)
  9. {
  10. for (int i = strlen(s) - 1; i >= 0; i--) {
  11. if (!isspace(s[i])) {
  12. s[i + 1] = '\0';
  13. break;
  14. }
  15. }
  16. }
  17.  
  18. int main(void)
  19. {
  20. char needle[64];
  21. fgets(needle, countof(needle), stdin);
  22. rstrip(needle);
  23.  
  24. // Тут ты открываешь файл, из которого будешь читать, а у меня stdin вместо него.
  25.  
  26. char line[1024];
  27. while (fgets(line, countof(line), stdin)) {
  28. rstrip(line);
  29. char *word = strtok(line, "=");
  30. char *translation = strtok(NULL, "");
  31.  
  32. if (!strcmp(needle, word)) {
  33. printf("Found translation for %s: %s\n", needle, translation);
  34. }
  35.  
  36. if (!strcmp(needle, translation)) {
  37. printf("%s is a translation of %s\n", needle, word);
  38. }
  39. }
  40. }
Success #stdin #stdout 0s 9424KB
stdin
test
one=один
two=два
test=тест
three=три
проверка=test
stdout
Found translation for test: тест
test is a translation of проверка