il please  Write a function insert( ) that takes three arguments: a character vector str1[100], a character vector str2[100], and an integer i. Your function insert ( ) inserts the string str2 within string str1 after the ith element of str1 ( i is >= 0). For example, if str1="abcd" and str2="123" and i=0, after calling insert( ) the character vector str would contain "a123bcd". If str1="abcd" and str2="123" and i=1, after calling insert( ) the character vector str would contain "ab123cd". Character vectors str1 and str2 can hold strings of any length up to 99 characters. If the length of str1 after insterting str2 would be

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I have the question and the answer what I want is to understand the logic of each line and explain the code to me in detail please 

Write a function insert( ) that takes three arguments: a character vector str1[100], a character vector str2[100],
and an integer i. Your function insert ( ) inserts the string str2 within string str1 after the ith element of str1 ( i is >= 0).
For example, if str1="abcd" and str2="123" and i=0, after calling insert( ) the character vector str would contain "a123bcd".
If str1="abcd" and str2="123" and i=1, after calling insert( ) the character vector str would contain "ab123cd".
Character vectors str1 and str2 can hold strings of any length up to 99 characters. If the length of str1 after insterting str2 would be
larger than 99, place the string "ERROR" in str1

this is the answer

#include<stdio.h>

#include<string.h>

void insert(char *str1,char *str2,int i)

{

int x=0,y=0;

int len=0;;

int k=0;

char temp[100];

y=i;

while(str2[x]!='\0')

{

x++;

}

len=x;

x=0;

while(str1[y]!='\0')

{

y++;

temp[k++]=str1[y];

}

//printf("%s",str1);

y=i;

while(str1[y]!='\0')

{

y++;

while(str2[x]!='\0')

{

str1[y++]=str2[x];

x++;

}

}

k=0;

//printf("\n%s",temp);

while(temp[k]!='\0')

{

if(y>99)

{

strcpy(str1,"ERROR");

break;

}

str1[y++]=temp[k];

k++;

}

}

int main()

{

char str1[100],str2[100];

int i;

printf("\nEnter str1 :");

scanf("%s",&str1);

printf("\nEnter str2 :");

scanf("%s",&str2);

printf("\nEnter i :");

scanf("%d",&i);

insert(str1,str2,i);

printf("\nstr is : %s",str1);

return 0;

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY