Thread: Using Dev-C++, I want to delete a character in array. I don't know what to do next.

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    4

    Using Dev-C++, I want to delete a character in array. I don't know what to do next.

    Code:
    include <iostream>
    
    using namespace std;
    
    int main ()
    {
        char word[3];
        char target;
        int hit;
        hit=0;
        cout << "Enter 4 letters" <<endl;
        cin >> word;
        cout << "Enter letter to delete" <<endl;
        cin >> target;
        for (int x=0;x<4;x++)
        {
            if (word[x]==target)
            {
                hit=1;
            }
        if (hit==1)
        {
            word[x]=word[x+1];
            cout << word <<endl;
            x++;
        }
        else
        {
            cout << "No match letter to delete" <<endl;
        }
        }
        system ("pause");
        return 0;
    }
    Sorry for being noob. I can study and understand your answer.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I would suggest you re-read your other thread until you understand the points about buffer overrun.

    Because whilst it may seem that "it works" at the moment, you can be very sure that it still contains bugs which you haven't yet fixed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I remove a character from character array?
    By nick753 in forum C++ Programming
    Replies: 25
    Last Post: 12-08-2010, 11:27 AM
  2. Delete Character
    By Logikal in forum Linux Programming
    Replies: 1
    Last Post: 01-25-2010, 09:23 AM
  3. REmoving a character from a character array
    By Bladactania in forum C Programming
    Replies: 3
    Last Post: 02-11-2009, 02:59 PM
  4. Delete last Character (comma) ?
    By Hexxx in forum C Programming
    Replies: 2
    Last Post: 10-19-2003, 12:28 AM
  5. using delete to delete an array
    By iain in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2002, 03:53 PM