11_strings.c 571 B

1234567891011121314151617181920212223
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5. char str1[32];
  6. char str2[32];
  7. strcpy(str1, "String 1");
  8. strcpy(str2, "String 2");
  9. printf("String values are \"%s\" \"%s\"\n", str1, str2);
  10. int diff = strcmp(str1, str2);
  11. printf("First string is %s than second\n", (diff == 1 ? "bigger" : "less"));
  12. char str3[32];
  13. strcpy(str3, str1);
  14. strcat(str3, str2);
  15. printf("Concatenation of two strings is \"%s\"\n", str3);
  16. int ingpos = strstr(str3, "ing") - str3;
  17. printf("First occurrence of word ing in \"%s\" is at position %d\n", str3,
  18. ingpos);
  19. return 0;
  20. }