Write a program that extract a sub string from a given position.

/* Write a program that extract a sub string from a given position.
eg. “Working with string is fun” , then if from positoin 4, and 4 characters to be extracted,
that is “king”. If the number of charcters  to be extracted is 0 or negative then the program should
return whole string.
*/

#include<stdio.h>
main()
{
int i,n;
char str[100];
puts("Enter the string:: ");
gets(str);
printf("\nEnter the position from you wanna extract string:: ");
scanf("%d",&n);
if(n==0 || n<0) puts(str);
else for(i=n;i<n+n;i++)
printf("%c",str[i]);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s