Deleting duplicates from a string I'm pretty new, but I'm always looking for different/better ways to solve these problems as it helps me understand it better and hopefully will make me better programmer. Feel free to point out any mistakes or industry "dont's" as well.

#include &lt;cstdio&gt;
using namespace std;

//Function Prototypes
void deleteDupes(char message[], int msg_length);
int length(char message[]);

int main()
{
    //Declaring vars
    int msg_length = 0;
    char message[500] = "The dog jumped up and down and ate chocolate, then he bit the cat";

    //Display the original message and it's length
    msg_length = length(message);
    puts(message);
    printf("The message length before deleting the dupes is: %d\n\n", msg_length);

    //Deletes the duplicates and displays the new message and length
    deleteDupes(message, msg_length);
    msg_length = length(message);
    puts(message);
    printf("The message length after deleting the dupes is: %d\n", msg_length);

    return 0;
}//end main

//Function to determine the message length
int length(char array[])
{
    int i = 0;
    for(i; '\0' != array[i]; i++){}
    return i;
}

//Function to delete the duplicate char(s) from the array message
void deleteDupes(char message[], int msg_length)
{
    for(int i = 0; i &lt; msg_length; ++i)
    {
       for(int j = i + 1; j &lt; msg_length; ++j)
       {
           if(message[j] == message[i])
           {
               for(int k = j; k &lt; msg_length; ++k)
               {
                   message[k] = message[k + 1];
               }
            msg_length -= 1;
            --i;
           }
       }
    }
}
C++ is C++

A lot of this code is basically C. So let's C++ify it. &lt;cstdio&gt; is the C-style IO library. In C++, we have &lt;iostream&gt;, with cout. The biggie here is:

char message[500] = "The dog jumped up and down and ate chocolate, then he bit the cat";


C++ has a library for dealing with strings. It's called &lt;string&gt;, and is very useful:

std::string message = "The dog ...";


std::string manages its own memory and comes with a whole bunch of member functions. One of those is size():

size_t msg_length = message.size();
std::cout &lt;&lt; message &lt;&lt; '\n';
std::cout &lt;&lt; "The message length before deleting the dupes is: "
          &lt;&lt; msg_length &lt;&lt; "\n\n";


Although if you want to stick with pointers, you still wouldn't need to write your own length function as there is strlen. But if you really insist on writing your own loop, please put the thing you're comparing on the left-hand side:

for (; array[i] != 0; ++i) ;


Or, since we're comparing against 0:

for (; array[i]; ++i) ;


Putting constants on the left-hand side is, frankly, terrible.

deleteDupes

The C++ standard library comes with a whole bunch of algorithms. The algorithms tend to be very useful, both in terms of code readability, performance, and correctness. For one thing, your loop has a bug (you have --i which presumably should be --j).

I would use the Erase-Remove idiom. That is:

void deleteDupes(std::string&amp; message) {
    message.erase(
        std::remove_if(message.begin(), message.end(), ???),
        message.end()
        );
}


What do we put in the ???s? We need a predicate that will return true if this is a character we've seen before. Easy way of keeping track of that is an std::unordered_set and thanks to C++11, we can stick the predicate in-line:

void deleteDupes(std::string&amp; message) {
    std::unordered_set&lt;char&gt; seen;
    message.erase(
        std::remove_if(message.begin(), message.end(), [&amp;](char c){
            return !seen.insert(c).second;
        })
        message.end()
        );
}


Basically, insert will tell you if it succeeded or not (i.e. this is the first time you've seen c or not). If it's the first time, we return false (and insert into our set). Otherwise, we return true and the remove_if algorithm marks this character for deletion. We then erase all the dupes in one go. 

Simple. Correct. Readable.