Program in C to insert a character in string at given position
#include<stdio.h> #include<string.h> int main() { char str[100],data; int position,i,length=0; printf("Enter a string:-"); scanf("%s",str); printf("Enter a character and position where we would data insert. :-"); fflush(stdin); scanf("%c%d",&data,&position); printf("\nBefore inserrtion = %s\n",str); length=strlen(str); for(i=length;i>=position-1;i--) { str[i]=str[i-1]; } str[position-1]=data; str[length+1]='\0'; printf("\nAfter inserrtion = %s",str); return 0; }
Output:-
Related Programs
1 Comments