So I finished my project, which I don't believe is due until Thursday. Anyways, I went above and beyond and did all of the extra credit. It was really simple except I had some problems with strings.
Warning, programmer talk ahead!
This is my learning experience, it may one day help someone else.
When using BASIC style languages like darkBASIC, Visual Basic, and Gambas, strings are real easy to deal with. I'm not saying strings are hard in C++, they just don't work quite the way you would think they would. I'm talking about assignment. It's real easy to put a string literal into a character array in C++ when you declare it.
Something like this:
char string[10] = "my string";
Works well, no problems at all. You can even assign it some user input with the cin command.
cin >> string;
The problem is when you want to assign it with something specific. Normally, variables can be assigned this way:
int number;
number = 1;
The variable 'number' now has the value of 1. I figured I could do the same with strings.
string = "new string";
Oh no. You get an error saying you converted a char constant to a char. Yeah. This kind of approach works just fine in my basic style languages.
Me, being the stubborn jerk I am, decided not to ask my teacher about any of this stuff and to just figure it out on my own. I'd list other way's I tried but they are wrong and are of no use to anybody. Anyways, I found a site that showed me how to do it the right way. Hurray the internet!
strcpy(string, "new string");
Oy. That is the proper way of doing it. Not any more difficult than an assignment, just a pain because I didn't know it.
END PROGRAMMER TALK.
My project is done, and is cross-platform. It runs on Linux and Windows.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment