this prog. is supposed to demonstrate a strcpy error...however im getting an error and it wont run....once again im suing a dev c++ bloodshed compiler.
and heres my code....once again i know it has a strcpy error thats the reason for writting the program..to demonstrate a char array overflow.

strerror.cpp

#include <iostream>
#include <string>

int main()
{
    char student_name[21] = "Brandon Adkins"; //declare four
    char city[] = "Lubbock";
    char state[3] = "TX";
    char ZIP_code[11] = "79413-3640";

    cout << student_name << '\n'; //display the strings
    cout << city << '\n';
    cout << state << '\n';
    cout << ZIP_code << '\n';

    strcpy(state,"California"); //copy a string that is too long
                                //into the state char. array.

    cout << student_name << '\n'; //display the strings again
    cout << city << '\n';         //showing the overwritten array.
    cout << state << '\n';
    cout << ZIP_code << '\n';

    cin.get();
    cin.get();
    return 0;
}

so wiser ones....whats the problem now....
(side not....dev compiler is sooo annoying...i messed around with a visual studios compiler and it was more user friendly....)
im going out of a book here but unfortunately it doesnt support devs picky code. it doesnt say what dev needs extra for the code i write...like the cin.get(); command..these things are not listed..sorry to waste time...peace

You're forgetting using namespace std; after #include

hahaha...your right, we all make mistakes sometimes...jeez, im stupid.
?ょよ

Actually quite an interesting code. After the correction the code will compile. BTW in this case you only need one cin.get() for the console to wait, since there is no enter to trap.

At least on my machine there is no effect after using just
strcpy(state,"California");
or even
strcpy(state,"CaliforniaCalifornia");
but after
strcpy(state,"CaliforniaCaliforniaCalifornia");
the extra long state string starts overwriting the city and if you use four Californias in the state string it will hit the name too.

hahaha...your right, we all make mistakes sometimes...jeez, im stupid.
?ょよ

That didn't translate very well. What does your bee do exactly?

>to demonstrate a char array overflow.
Array overflow is undefined. Your demonstration is non-sensical because the result could be anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.