P
P
Peter12112020-12-03 12:45:21
C++ / C#
Peter1211, 2020-12-03 12:45:21

How to insert a new word between the first and second word in an arbitrary text?

Can't write program

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Ananiev, 2020-12-03
@SaNNy32

Text is a list of words. Therefore, the task is reduced to inserting a word into a list.

C
CityCat4, 2020-12-03
@CityCat4

Damn, is there a group of students dug in, which now has the topic "working with text"?
man realloc, dude,
either read the text, calculate how much it has increased, take memory for the new version, copy the word, insert a new word, insert the tail.
well, either "Freelance"

M
mayton2019, 2020-12-03
@mayton2019

Not surprising. The "C" language is generally poorly suited for text processing. The semantics of ASCIIZ-vectors is such that in order to insert "something" somewhere, you need to: Measure the size of the string. Measure the size of the inserted string. Allocate memory. Copy the old line to the new location with changes.
Modify a string in place... hmm.. not a good idea. I wouldn't advise. Makes code potentially dangerous. All the same it is better that the line was immutable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question