Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 40 41 [42] 43 44 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 96014 times)

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #615 on: December 17, 2010, 04:35:06 pm »

Hm. That's great. So, to give access to the database to a user on a different computer, I'll need a way to put the ElementsData into their home directory...
Getting the application's directory shouldn't be to hard. The full path to application is stored in argv[0], just save it as a string.

Oh... Why? Does it need it? The math library required by "math.h"?
It's kind of silly really. For some reason, you don't need the -lm flag on Windows, all you need to #include <math.h>. Seems to be a Linux thing.
« Last Edit: December 17, 2010, 04:36:52 pm by ILikePie »
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #616 on: December 18, 2010, 02:51:31 am »

Been a while since I passed data like that :) Try

int IO(char** cReturnValue[10]) for your function declaration.

Thanks, I think I fixed it.
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #617 on: December 18, 2010, 05:02:07 am »

Hm. That's great. So, to give access to the database to a user on a different computer, I'll need a way to put the ElementsData into their home directory...
Getting the application's directory shouldn't be to hard. The full path to application is stored in argv[0], just save it as a string.

Oh... Why? Does it need it? The math library required by "math.h"?
It's kind of silly really. For some reason, you don't need the -lm flag on Windows, all you need to #include <math.h>. Seems to be a Linux thing.
Can you say how reliable argv[0] is? Google seems to think that it can be pretty random, depending on where and how the application was launched.

On another note, I'm so tired of this bullshit (including not-reading files) that I'm even considering changing the language. Anyone can suggest what I could kind of easily transfer my... newly-acquired knowledge of C++ into? I don't exactly have a lot of time to dawdle around, so even if I solve my current problems, am I going to have to jump through hoops with the intricacies of C++ the rest of the way?

I'm considering going back to Object Pascal, as I programmed in it... like 5 years ago. But I haven't been able to find any good educational sources to supplement my beginner book, and Delphi books I've seen deal mostly with databases which is not exactly up my valley.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #618 on: December 18, 2010, 05:06:43 am »

There's C-Sharp, or D. Hell, even Python. Any C relative will to, AFAIK.

I eliminated the errors and all I get are warnings about strtok being depreciated. But when I run it, immediately after it posts the room description it crashes. What am I doing wrong?

Code: [Select]
#include "stdafx.h"
#include <string.h>
#include <iostream>

using namespace std;

int IO(char* cReturnValue[10]);

int testRoom()
{
    cout << "This is the test room! You find yourself surrounded by gray walls." << endl;
    cout << "There is a single, naked LIGHT bulb on the ceiling, and a CRATE on the floor next to you." << endl;
    cout << endl;
   
    char *cInputTokens[10];
    do
    {
IO(&*cInputTokens);
if (cInputTokens[0] == "get")
           {
               if (cInputTokens[1] == "crate")
                   cout << "The crate is too heavy to lift." << endl;
               else if (cInputTokens[1] == "light")
                   cout << "Ouch! The light bulb is too hot to touch." << endl;
   else
   cout << "I don't recognise that item." << endl;
           };
if (cInputTokens[0] == "die")
{
cout << "You die." << endl;
break;
};
    }while(0 == 0); //Make an exit condition.
return 0;
}
       
int IO(char* cReturnValue[10])
{
    char* cIOline = "\0";
    cin.getline(cIOline, 80);
    int nFinger = 0;
    cReturnValue[nFinger] = strtok(cIOline, "   ,.;:");
    do
    {
        cReturnValue[++nFinger] = strtok(NULL, "  ,.;:");
    }while(nFinger == 8);
return 0;
}

int main()
{
testRoom();
return 0;
}
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #619 on: December 18, 2010, 05:16:49 am »

Can you say how reliable argv[0] is? Google seems to think that it can be pretty random, depending on where and how the application was launched.
It isn't really random, it just stores the command you typed into the terminal.
Spoiler (click to show/hide)

Also, if you really want to drop C++, I'd go with Java.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #620 on: December 18, 2010, 06:33:53 am »

Looks like my Bresenham is broken, here it is. It draws only straight lines from x1, y1 to x2 - 1, y2 (or y2 -1). Anyone mind looking at it?
« Last Edit: December 18, 2010, 06:45:27 am by ILikePie »
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #621 on: December 18, 2010, 07:05:25 am »

I eliminated the errors and all I get are warnings about strtok being depreciated. But when I run it, immediately after it posts the room description it crashes. What am I doing wrong?

At some point I'll try compiling your code and checking but off the top of my head this is probably the error

Code: [Select]
    char* cIOline = "\0";
    cin.getline(cIOline, 80);

Your reading (upto) 80 characters into a char* which points at a single character space. (And depending on your compiler a constant single character too)

Code: [Select]
char cIOline[80];
memset(&cIOline, 0, 80);
cin.getline(&cIOline, 80);

This might work, for some reason my brain isn't sure if you need the & or not but one of either with or without it will work.

Code: [Select]
std::string cIOline;
cin >> cIOline;

Alternatively this should read the next line of set of characters regardless how long.

Looks like my Bresenham is broken, here it is. It draws only straight lines from x1, y1 to x2 - 1, y2 (or y2 -1). Anyone mind looking at it?

Code: [Select]
for (int x = x1; x < x2; x++)It will never draw to x2 without x <= x2, this will also stop it at y2 -1 with certain deltas.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #622 on: December 18, 2010, 08:59:53 am »

Code: [Select]
for (int x = x1; x < x2; x++)It will never draw to x2 without x <= x2, this will also stop it at y2 -1 with certain deltas.
Aye, that did it, thanks. Now my flood fill is broken (Here). For some reason, it gives a java.lang.StackOverflowError unless I comment out one of the four calls (eg. fill (x - 1, y, Canv, Target, Current) ). Am I missing something?
Also, I really don't want to drop recursion unless it's a must.
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #623 on: December 18, 2010, 11:49:45 pm »

so yea, perhaps

char[200] buffer = "\0";
char * = buffer;

would be a good idea

Also strings are supposed to be constant, and therefore you are not supposed to write to them

according to people on the internet,

char *x =string;
x[0]='q';
is liable to give errors/break/not work.

« Last Edit: December 19, 2010, 12:21:24 am by eerr »
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #624 on: December 19, 2010, 05:22:17 am »

So, I gave a (lame) go to Java yesterday, installed NetBeans. Tutorials above starter confusing. So, my question to ILikePie... or Ron, and anyone else in Java, is it a good idea to try to learn and use java DB thingy for my... well, elements, and eventually chemical compounds, databases? Or maybe it's called CRUD. I'm not sure. And if that converts well to mobile edition.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #625 on: December 19, 2010, 05:25:29 am »

ARGLEBARGLEARGLEBARGEARGLEBLARGLEBLARGARGARGARGBLARG

This is really annoying me. It's stopped crashing. but now it won't recognise any of my commands. I'm positive I'm doing something wrong here, but I don't know what.

Wat do?

Code: [Select]
#include "stdafx.h"
#include <string.h>
#include <iostream>

using namespace std;

char* IO();

int testRoom()
{
    cout << "This is the test room! You find yourself surrounded by gray walls." << endl;
    cout << "There is a single, naked LIGHT bulb on the ceiling, and a CRATE on the floor next to you." << endl;
    cout << endl;
   
    char *cInputTokens[10];
    do
    {
cInputTokens[0] = IO();
if (cInputTokens[0] == "get")
{
if (cInputTokens[1] == "crate")
cout << "The crate is too heavy to lift." << endl;
else if (cInputTokens[1] == "light")
cout << "Ouch! The light bulb is too hot to touch." << endl;
else
cout << "I don't recognise that item." << endl;
};
if (cInputTokens[0] == "die")
{
cout << "You die." << endl;
break;
};
    } while(0 == 0); //Make an exit condition.
return 0;
}
       
char* IO()
{
char* cReturnValue[10];
char cIOline[80];
memset(&cIOline, 0, 80);
cin.getline(cIOline, 80);
    int nFinger = 0;
    cReturnValue[nFinger] = strtok(cIOline, "   ,.;:");
    do
    {
        cReturnValue[++nFinger] = strtok(NULL, "  ,.;:");
    } while(nFinger == 8);
return cReturnValue[0];
}


int main()
{
testRoom();
return 0;
}
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #626 on: December 19, 2010, 05:27:49 am »

char[200] buffer = "\0";
char * = buffer;

I'm not even sure that should compile as your making a char[200] equal a const char[1] even if it does only the first character will be \0 which isn't what you want.

Code: [Select]
char[200] buffer;
memset(buffer, 0, sizeof(buffer));

Should do what your trying to achieve.

Also strings are supposed to be constant, and therefore you are not supposed to write to them

const strings are suppose to be constant, as are literal strings (anything in a quotes such as char* literal_string = "hello world"). Any string object that isn't a const, any non const character array or any character pointer to an area of mallocated memory you can write to as you wish.

char *x =string;
x[0]='q';
is liable to give errors/break/not work.

Assuming string is a literal then yes, although with one character it probably wouldn't crash a good compiler should still throw a warning. However if you replaced the char* with std::string it should just work.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #627 on: December 19, 2010, 08:43:52 am »

So, I gave a (lame) go to Java yesterday, installed NetBeans.
I've never used NetBeans, but I'd say the best Java IDE out there is Eclipse. It's got Microsoft-like Intellisense, it puts together Maven packages for you, and it's got a frontend for the Java debugger. It's a bit big, but it's amazing.
I myself use Emacs, but that's because I dislike IDEs, and can work much faster when I have every command mapped to a keystroke.
Tutorials above starter confusing. So, my question to ILikePie... or Ron, and anyone else in Java, is it a good idea to try to learn and use java DB thingy for my... well, elements, and eventually chemical compounds, databases? Or maybe it's called CRUD. I'm not sure. And if that converts well to mobile edition.
Java and C++ are very similar in syntax, start by converting what you have to Java code. I'd just skip the tutorials and go straight to writing. If something doesn't compile, look it up.
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #628 on: December 19, 2010, 10:25:27 am »

So, I gave a (lame) go to Java yesterday, installed NetBeans. Tutorials above starter confusing. So, my question to ILikePie... or Ron, and anyone else in Java, is it a good idea to try to learn and use java DB thingy for my... well, elements, and eventually chemical compounds, databases? Or maybe it's called CRUD. I'm not sure. And if that converts well to mobile edition.

Netbeans and eclipse are both good and have strong Java support.

Using Java db depends mostly on your goals. The strengths of databases are the way you can search, sort and collate the information within them however the data you have may not fix very well onto a relational model. I'd need more information one what your trying to do. However for purely storage then yes I'd suggest using a database, certainly over trying to write your own file format.

For a preference I tend to use sqllite as it's simple local file storage and free to use however the interface for them all is the same through Java so feel free to use Java DB instead, I've not used that one as such so can't really offer a comparison compared to others.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #629 on: December 19, 2010, 10:57:08 am »

Actually... there's a couple of problems with what I want to do with the database, and one I've just come up with, another I couldn't address in C++. I think I'm going to divide my elements into groups, that is, classes inheriting from a common element class, but I'd like to store their data in one file. Which means that entries might have variable sizes. Or maybe I could fit them all into one class still... I'd sure prefer a premade storage format that the system already knows how to read, because my efforts at teaching it to read a format proposed by me have been unproductive. On C++.

Ideally, I'd like to have the database so that it's editable and accessible for the developer, but the user can't do anything with it (that's why I don't want to do it in text format).
Logged
Pages: 1 ... 40 41 [42] 43 44 ... 78