Saturday, May 21, 2011

C Program to produce a substring from given string

/*Write a program to copy m consecutive characters from String S1
beginning at position n into another string S2.*/

int main()
{
int m,n,i;
char s2[40],s1[40];
printf("Enter the string 1");
scanf("%s",&s1);
printf("\nHow many characters you want to copy");
scanf("%d",&n);
printf("From which position you want it to be copied");
scanf("%d",&m);
for(i=m-1;i {

s2[i-m-1]=s1[i];
}

printf("\nThe string s2 is %d",puts(s2));
system("pause");
return 0;
}

No comments:

Post a Comment

Google+ Followers