// Slicing : write a function named slice, which takes string &
// returns a sliced string from index n to m
#include <stdio.h>
#include<string.h>

void slice(char str[],int n, int m); 
int main() {
    char str[100];
    int a,b;
    scanf("%s",&str); //throws an error but gives needed output
    printf("\nEnter range to slice the given string: ");
    printf("\nEnter a:");
    scanf("%d",&a);
    printf("\nEnter b:");
    scanf("%d",&b);
    slice(str,a,b);

    
    return 0;
}
void slice(char str[], int n, int m){ //n and m are valid value
    char newStr[100];
    int j=0;
    for(int i=n; i<=m; i++, j++){
        newStr[j] = str[i];
    }
    newStr[j]='\0';
    printf("\n");
    puts(newStr);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: