From 7e381dc433d5fbc10b0b1f75eaa7d06970a2bc48 Mon Sep 17 00:00:00 2001 From: Aurelius Date: Sat, 27 Jun 2026 11:15:16 +0530 Subject: [PATCH 1/2] Fix slice function logic in Chapter 8 Practice Set Question 4 --- Chapter 8 - Practice Set/04_problem4.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Chapter 8 - Practice Set/04_problem4.c b/Chapter 8 - Practice Set/04_problem4.c index 807a974..5f10060 100644 --- a/Chapter 8 - Practice Set/04_problem4.c +++ b/Chapter 8 - Practice Set/04_problem4.c @@ -2,14 +2,10 @@ char* slice(char str[], int m, int n){ - int i=0, count; - char *ptr1 = &str[m]; - char *ptr2 = &str[n]; + str = &str[m]; + str[n-m+1] = '\0'; - str = ptr1; - str[n] = '\0'; return str; - } int main(){ char str[] = "Harry bhai"; From 980292af487e8b527f5f8ed4aa826f39a6baade1 Mon Sep 17 00:00:00 2001 From: Aurelius Date: Sat, 27 Jun 2026 11:23:25 +0530 Subject: [PATCH 2/2] Fix Chapter 8 practice set problem 4 slicing logic --- Chapter 8 - Practice Set/04_problem4.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Chapter 8 - Practice Set/04_problem4.c b/Chapter 8 - Practice Set/04_problem4.c index 5f10060..6ce2254 100644 --- a/Chapter 8 - Practice Set/04_problem4.c +++ b/Chapter 8 - Practice Set/04_problem4.c @@ -1,15 +1,15 @@ #include - char* slice(char str[], int m, int n){ - str = &str[m]; - str[n-m+1] = '\0'; + char *ptr = &str[m]; + ptr[n - m + 1] = '\0'; - return str; + return ptr; } + int main(){ - char str[] = "Harry bhai"; - - printf("%s", slice(str, 1, 7)); + char str[] = "Himanshu Srivastav"; + + printf("%s\n", slice(str, 6, 11)); // Output: hu Sri return 0; } \ No newline at end of file