#include<stdio.h>
#include<conio.h>
#include<string.h>
char substr(char *p, int s, int n);
void main()
{
char str[50];
int start,no_of_chars;
clrscr();
printf(" \n \n Enter the string: \t ");
gets(str);
printf(" \n \n Enter start position for substring: \t ");
fflush(stdin);
scanf(" %d ",&start);
printf(" \n \n Enter number of characters: \t ");
fflush(stdin);
scanf(" %d ",&no_of_chars);
substr(str,start,no_of_chars);
getch();
}
char substr(char *p, int s, int n)
{
int i;
printf(" \n \n The substring is: \t ");
for( i = s - 1; i < n;i++)
{
printf("%c",p[i]);
}
return 1;
}
OUTPUT:
Enter the string: Please Mention Your Address:
Enter start position for substring: 20
Enter number of characters: 7
The substring is: Address
ALSO READ:
Sample C Program To Swap Two Strings Using strcpy() Function.
Sample C Program To Sort A Given Number Of Strings Using strcmp() Function.
Sample C Program To Display Array Of Strings.
Sample C Program To Convert String To An Integer Using atoi() Function.
Sample C Program To Find The Length Of A String.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com