Insert substring into a string - C Language Programming

Program in C Language to insert substring into a string

Click here to open this program in Turbo C++

Statement - Insert substring into a string
Programmer - Vineet Choudhary
Written For -

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void insert_substring(char*, char*, int);
char* substring(char*, int, int);
void main()
   char text[100], substring[100];
   int position;

   printf("Enter some text\n");
   printf("Enter the string to insert\n");
   printf("Enter the position to insert\n");
   scanf("%d", &position);
   insert_substring(text, substring, position);
void insert_substring(char *a, char *b, int position)
   char *f, *e;
   int length;
   length = strlen(a);
   f = substring(a, 1, position - 1 );      
   e = substring(a, position, length-position+1);
   strcpy(a, "");
   strcat(a, f);
   strcat(a, b);
   strcat(a, e);
char *substring(char *string, int position, int length) 
   char *pointer;
   int c;
   pointer = malloc(length+1);
   if( pointer == NULL )
   for( c = 0 ; c < length ; c++ ) 
      *(pointer+c) = *((string+position-1)+c);       
   *(pointer+c) = '\0';
   return pointer;
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.