diff --git a/Chapter 8 - Practice Set/04_problem4.c b/Chapter 8 - Practice Set/04_problem4.c index 807a974..6ce2254 100644 --- a/Chapter 8 - Practice Set/04_problem4.c +++ b/Chapter 8 - Practice Set/04_problem4.c @@ -1,19 +1,15 @@ #include - char* slice(char str[], int m, int n){ - int i=0, count; - char *ptr1 = &str[m]; - char *ptr2 = &str[n]; - - str = ptr1; - str[n] = '\0'; - return str; + char *ptr = &str[m]; + ptr[n - m + 1] = '\0'; + 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