Char book exercise, getting weird error?

I am running into a strange error with the follow c++ exercise:

Write a program that asks the user to enter his or her first name and then last name, and
that then constructs, stores, and displays a third string, consisting of the user’s last name
followed by a comma, a space, and first name. Use char arrays and functions from the
cstring header file. A sample run could look like this:
Enter your first name: Flip
Enter your last name: Fleming
Here’s the information in a single string: Fleming, Flip


my code is as follows :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    cout << "Enter your first name: ";
    char fname[20];
    cin.getline(fname, 20);
    cout << "Enter your last name: ";
    char lname[20];
    cin.getline(lname, 20);
    char fullname[40];
    strcat(lname, ", ");
    strcpy(fullname, lname);
    strcat(fullname, fname);
    cout << "Here is the information in a single string: " << fullname << endl;

    return 0;
}



Here is a picture of my error (since I can't figure out the character codes)
http://imageshack.us/photo/my-images/135/wtflb.jpg/

As you can see.. it doesn't just display last name, first name. It has some strange characters prior to lname.

Can anyone shed some light on what I have messed up?
I see nothing wrong with it, and it actually works as expected @ ideone.com: https://ideone.com/D45u0 .

I got the expected result.
Thanks for the reply, I am going to bookmark that website for future errors. I was banging my head against my desk here!
Topic archived. No new replies allowed.