answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

main()

{

char mainstr[100],insstr[30],temp[50];

int l1,l2,l,i,j,pos;

clrscr();

printf("Enter a main string:");

gets(mainstr);

printf("Enter the sub string:");

gets(insstr);

printf("\n Enter the position to be inserted:");

scanf("%d",&pos);

l2=strlen(insstr);

l1=strlrn(mainstr);

if(pos>l1)

{

for(i=0;i<l2;i++)

mainstr[i++]=insstr[i];

}

else

{

for(i=0;i<pos;i++)

temp[i]=mainstr[i];

for(j=0;j<l2;j++,i++)

temp[i]=insstr[j];

for(j=pos;j<l1;j++,i++)

temp[i]=mainstr[j];

temp[i]=NULL;

printf("After insertion the string is:");

puts(temp);

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: To insert a sub-string in to given main string from a given position?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Music & Radio

What is string efficiency?

string efficiency refers to the efiiciency of the string which is an assembly of two or more number of insulation disc used between the tower and conductor . it is given by the formula , string efficiency = voltage across the string / number of disc in the string * voltage across the disc nearest the string .


What are rhyming strings?

What words rhyme with the given words to make a string. Like hat, mat, sat,


The rate at which something vibrates?

Is different depending on the material's length, thickness and the forcing function. Each of the 5 guitar strings, for example, vibrates at a different frequency also known as pitch. Additionally, you can change the pitch of a given string by effectively shortening it when you press the string against a fret.


What type of ukulele did George Harrison use?

George Harrison liked the Kamaka ukuleles. He played the concert size as well as the the tenor, both a 6-string and 8-string. He often would go into a music store on Maui, Hawaii and buy every Kamaka in stock to give to his friends. He was known to have given them to John and Paul and recently Paul has been playing his.


On a 5 string bass guitar what are the notes on the E string?

The same as on a 4 string.E F F# G G# A which is where the A string takes over and continues up in semitones. The 5th fret of each string is the same as the next string open, except where the B string is involved (the 5th string). If the B is the highest pitched string on the guitar then its open note is the same as the G strings 4th fret, not 5th

Related questions

What is th function of the charindex?

The CHARINDEX function in SQL is used to find the position of a specific character or substring within a string. It returns the starting position of the substring or character within the given string.


How do you write a C program to insert a sub-string into given main string from a given position?

#include#includevoid 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


How would you implement a substr function that extracts a sub string from a given string?

substr(string, position [, count]) It extract substring starting from start and going for count characters. If count is not specified, the string is clipped from the start till the end


Do I need to write a program to find a substring in a given string in c plus plus?

No.


What is substr function does in c?

it will give the substring of length(as per the user) from the actual string,and the starting length from where it has to copy the substring from actual should be given by the user.


Write a Java Program to find occurences of given word in a text?

Check the documentation of the String class, for a method that searches for a substring.


Python Substring: What is a Substring in Python?

One of the most used types in the Python language is the string. Characters can be figuratively enclosed in quotation marks to create strings. Python treats single quotes the same way it treats double-quotes. In Python, creating strings is as simple as assigning a value to a variable. For Example: Variable1 = &quot;Hello world&quot; Variable2 = &quot;Welcome to the world of Python.&quot; What is a Substring? Just picture what a car manufacturer does to quickly and effectively determine the last five digits of a chassis number. The idea of Substring conceals the answer to this puzzle. According to proper language analysis and computer science, a substring is a sequence of characters included within a string. In other words, a substring can be defined as a portion of a string that is created using one of the methods listed by the Python string, which also determines the substring index and other details. A component or subset of a string is another method to define a substring. The substring process includes any changes made to text data that make up a string. For example: &quot;This work is excellent. We must pursue it. It is a particular kind of string, and &quot;We must pursue it&quot; is a particular kind of Substring. Slicing is a Python function that can be used to extract a substring. Programmers frequently desire to divide the data into separate pieces for a particular reason. For instance, if a developer needs to use only the user's first name and has data that includes the user's whole name, the developer will need to divide the data into two pieces, such as the user's forename and surname. The challenge that arises now is how a Python programmer will carry out this task. The correct response is that a developer must engage in &quot;string slicing&quot; to complete this task. String slicing is a Python technique for extracting a specific portion of a string, which is then utilized as a &quot;substring.&quot; How is a Substring created from a String that is provided? Python supports several methods for creating a substring from a string. But the slicing process is one of the most used methods in Python for creating a substring from a string. Slicing in Python Based on their position in a string, a software developer can access the characters within it at any time. Characters are assembled into strings. The term for this is indexing. The indexing method in Python returns a one-character string from the supplied offset or location. Now, slicing is the technique used to do this action when a portion of a string, rather than simply a single character, is required. What is String Slicing In Python? Slices, which return a complete necessary chunk in a single step rather than a single item, might be considered a generalized indexing type. Slicing allows for the execution of various tasks, including the extraction of data columns, the removal of leading and trailing characters, and many more. Slicing relies on a very basic idea. A new string object containing the section indicated by the offset pair is returned by Python when a string is indexed using a pair of offsets separated by a colon (:). The right offset's upper bound is non-inclusive in the offset pair, whereas the left offset's lower bound is included. Therefore, the left and right boundaries will default to values of 0 and the length of the string you are slicing, respectively, if neither of the offsets is given. Let's get into the specifics to comprehend the Slicing operator's syntax. Syntax of Slicing Operator As we have previously read earlier, the slicing operator is thought to be one of the best ways to create a substring. Let's examine the slicing operator's syntax: String(steps, startIndex, endIndex) where, • startIndex: This is the Substring's initial index. The character is a part of the Substring at this index. StartIndex is presumed to be equal to 0 if it is not set. • endIndex: This is Substring's final index. The character is absent from the Substring at this index. If the endIndex value is left blank, it is automatically considered equal to the length of the entire string. • Step: After the first character is extracted from the string, it is known how many characters to proceed with. The default setting is 1. Interested in becoming a data scientist? To learn more about Substring and other Python methods, enroll in a data science course in Mumbai, please visit Learnbay.co


How do you take substring from a given string in php?

Use the substr function. For example &lt;?php $name= "naruto uzumaki"; echo substr($name, 0, 6) ; // The first six char are taken by this code ?&gt; This will output naruto


Any five string related function in vb?

String-valued functions return NULL if the length of the result would be greater than the value of the max_allowed_packet system variable. For functions that operate on string positions, the first position is numbered 1. 1,ASCII(str)-Returns the numeric value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL. ASCII() works for characters with numeric values from 0 to 255.1. SELECT ASCII('2&prime;); 2,BIN(N)-Returns a string representation of the binary value of N, where N is a longlong (BIGINT) number. SELECT BIN(12); 3,BIT_LENGTH(str)-Returns the length of the string str in bits.SELECT BIT_LENGTH('text'); 4,CHAR(N,&hellip;)-CHAR() interprets the arguments as integers and returns a string consisting of the characters given by the code values of those integers. NULL values are skipped.1.SELECT CHAR(77,121,83,81,'76&prime;);SELECT INSERT('Quadratic', 3, 4, 'What'); 5,INSERT(str,pos,len,newstr)-Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr.


What is cprogram code to insert a node in single link list?

Write Code to Insert a Node in a Single Linked List at any given Position.


Find vowel from given string in C plus plus language?

std::string test ("The cat sat on the mat"); std::string vowels ("aeiouAEIOU"); size_t pos = test.find_first_of (vowels); if (pos != test.npos) std::cout &lt;&lt; "Vowel found at position " &lt;&lt; pos &lt;&lt; std::endl;


How do you get odd ascii letters from a given string using string copy?

there is no such method using string copy