From 26756b80614bdadd8a91024eb6ace04dd886fc6f Mon Sep 17 00:00:00 2001 From: anuj200-code <115894921+anuj200-code@users.noreply.github.com> Date: Sun, 5 Oct 2025 15:50:45 +0530 Subject: [PATCH] Create substring_in_array.c --- substring_in_array.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 substring_in_array.c diff --git a/substring_in_array.c b/substring_in_array.c new file mode 100644 index 0000000..8ed20af --- /dev/null +++ b/substring_in_array.c @@ -0,0 +1,27 @@ +#include +#include + +int main() { + char str[100], substr[50]; + + // Input main string + printf("Enter the main string: "); + fgets(str, sizeof(str), stdin); + str[strcspn(str, "\n")] = '\0'; // remove trailing newline + + // Input substring + printf("Enter the substring to search: "); + fgets(substr, sizeof(substr), stdin); + substr[strcspn(substr, "\n")] = '\0'; // remove newline + + // Use strstr() to find substring + char *pos = strstr(str, substr); + + if (pos != NULL) { + printf("Substring found at position: %ld\n", pos - str + 1); // 1-based index + } else { + printf("Substring not found.\n"); + } + + return 0; +}