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 demonstrate a char array overflow.


#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';

    return 0;

so wiser ones....whats the problem now....
(side 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 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
or even
but after
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.