Answers:
/* Use printf() to print the first 11 characters of source_str. */ printf(?First 11 characters: ?%11.11s?n?, source_str);
by using extract method we can extract a part from the string strextract(3,7)
 Posted by: vani
Contact vani
this is an uncomplied version.... int i=0,j=0,p; char *s; printf("Enter the String"); scanf("%s",&s); printf("
Enter the start and end of the string: "); scanf("%d %d",&i,&j); for(p=i;p<=j;p++) { printf("%c",*(s+p); } getch() }
 Posted by: rohan sekhri
Contact rohan sekhri
Another solution would be to use strncpy() to copy the part of the string and print it. Below is the code snippet. int main() { char a1[20]; char a2[20]; strcpy(a1,"HelloWorld"); printf("%s
",a1); strncpy(a2,a1,5); printf("%s
",a2); }
 Posted by: SPN
Contact SPN
The following is much simpler method of printing part of a string. int main(void) { char *ptr = "This is a test string"; /* partial string printing */ printf("String = %s
", &ptr[10]); return 0; } This prints: "test string"
 Posted by: Ravi A Joshi
Contact Ravi A Joshi
#include"string.h" void main() { int st_index; int end_index; char *str; char* substr(char*,int,int); printf("enter string"); scanf("%s",str); printf("enter start index and end index:"); scanf("%d %d",&st_index,&end_index); printf("the substring is: %s",substr(str,st_index,end_index)); //end of main } //function definition substr(char *temp,int temp1,int temp2) { int i,j=0; char *substr; for(i=temp1;i<=temp2;i++) *substr[j++]=*temp[i]; *substr[j+1]='/0'; return substr; } }
 Posted by: RAJU SAHANI
Contact RAJU SAHANI
If you have the better answer, then send it to us. We will display your answer after the approval.