//Without using Functions.
#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(string.h)
void main( )
{
char st[20],sub[10],temp[10];
int pos, i, j;
clrscr( );
printf("Enter the main string:");
gets(st);
printf("\nEnter the substring to insert:");
gets(sub);
printf("Enter the index position:");
scanf("%d",&pos);
if(pos<=strlen(st)) {
for(i=0;i<=strlen(st);i++) {
if(i==pos)
{
for(j=0;st[i]!='\0';j++) // to store the 'st' to 'temp' from given position.
{
temp[j]=st[i];
i++;
}
temp[j]='\0';
i=pos;
for(j=0;sub[j]!='\0';j++) // to insert a sub-str to main string.
{
st[i]=sub[j];
i++;
}
for(j=0;temp[j]!='\0';j++) // Lastly to insert the 'temp' to 'st' after sub-str.
{
st[i]=temp[j];
i++;
}
st[i]='\0';
}}
printf("\nAfter adding the sub-string: %s",st);
}
else
printf("\nSorry, it is not possible to insert a substring in that position.");
getch();
}
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Saturday, February 7, 2009
Subscribe to:
Post Comments (Atom)
program is good ....pls provide the logic for me....
ReplyDeletethe program doesn't word... i tried executing it... but it failed
ReplyDeletehow to print this pyramid in c
ReplyDelete1
25
368
47910
with out using functions is OK but will u provide it with using functions
ReplyDeletetotal rubbish !!!!! this idiot is just stretching dis short n simple progam !!!!
ReplyDeletesir this is too lenthy and takes lot of time for debugging can u minimise .
ReplyDeleteits tooo.... lengthy
ReplyDeletehow to write by using string manipulation functions
ReplyDeletei want to know about the output
ReplyDelete