Like Tree1Likes
  • 1 Post By Salem

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

This is a discussion on Using Dev-C++, I want to delete a character in array. I don't know what to do next. within the C++ Programming forums, part of the General Programming Boards category; Code: include <iostream> using namespace std; int main () { char word[3]; char target; int hit; hit=0; cout << "Enter ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    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.
    Elysia likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 10:27 AM
  2. Delete Character
    By Logikal in forum Linux Programming
    Replies: 1
    Last Post: 01-25-2010, 08:23 AM
  3. REmoving a character from a character array
    By Bladactania in forum C Programming
    Replies: 3
    Last Post: 02-11-2009, 01: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, 02:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21