Thread: how to delete elements from char array?

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    3

    how to delete elements from char array?

    how to delete elements from char array?
    for example if i had 6. elements in array and i need to deletе from 3. to 5. element?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,313
    The elements from indices 3 to 5 are the last three elements of the array of 6 elements, so it would suffice to reduce the value of the variable keeping track of the number of elements in use to 3, i.e., so that only the elements from indices 0 to 2 will be used. Hence, the other elements would have effectively been deleted. Of course, if you have elements that come after the deletion range, then you should copy them over.

    If this array stores a string, then you should also keep in mind that the string needs to be null terminated, though then you don't need a variable to keep track of the number of elements.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scan all elements in array for a specific char
    By ghost00359 in forum C Programming
    Replies: 8
    Last Post: 01-09-2016, 09:58 AM
  2. elements in char array?
    By mtjohnson88 in forum C Programming
    Replies: 3
    Last Post: 02-03-2011, 12:29 PM
  3. Help with creating a dynamic array that can add and delete elements
    By cloudstrife910 in forum C++ Programming
    Replies: 6
    Last Post: 11-18-2010, 09:01 PM
  4. Assign value of multiple char array elements to int
    By 3saul in forum C Programming
    Replies: 3
    Last Post: 02-03-2006, 05:31 AM
  5. ? comparing elements of a char array
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-20-2001, 07:55 AM

Tags for this Thread