-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring7.c
More file actions
29 lines (29 loc) · 814 Bytes
/
string7.c
File metadata and controls
29 lines (29 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Write a function named slice, which takes a string and returns a sliced string from n to m.
#include<stdio.h>
#include<string.h>
void slice(char str[],int index1,int index2); //index1=n,index2=m.
int main()
{
char a[17];
int index1,index2;
printf("Maximum length of string should not be exceed 16 characters \n");
printf("Enter your string : ");
fgets(a,50,stdin);
printf("Enter starting index for slicing : ");
scanf("%d",&index1);
printf("Enter end index for slicing : ");
scanf("%d",&index2);
slice(a,index1,index2);
return 0;
}
void slice(char str[], int index1,int index2)
{
char sliced[17];
int i,j=0;
for(i=index1;i<=index2;i++,j++)
{
sliced[j]=str[i];
}
sliced[j]='\0';
printf("Sliced string is as : %s \n",sliced);
}