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 ... 42 43 [44] 45 46 ... 78

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

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #645 on: December 19, 2010, 03:34:57 pm »

Well, I intend the program as an accessible editing interface. So that I, or someone else, if I shared responsibility, could fill the database without bothering with the format. But I guess now it's going to be my project to test if I'm able to make the program read/write my files.
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #646 on: December 19, 2010, 05:42:03 pm »

Code: [Select]
cReturnValue[nFinger] = strtok(cIOline, "   ,.;:");   
do    {       
      cReturnValue[++nFinger] = strtok(NULL, "  ,.;:");   
} while(nFinger == 8);


while (nFinger==8)? does nFinger ever == 8?

Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #647 on: December 19, 2010, 05:43:27 pm »

Note that he uses ++nFinger instead of nFinger++
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #648 on: December 19, 2010, 06:23:49 pm »

Is that a bad thing?

EDIT: Whoops, I see it now. I'm so derptarded.
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #649 on: December 20, 2010, 04:26:55 am »

Oh. Wow. Binary? I hope java won't screw up string output like C++.

What where you doing that made you think this? Because c++ will just output what you tell it, it won't screw it up on it's own.
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 #650 on: December 20, 2010, 04:52:07 am »

Well, trying to print a class containing a string (like a char string or String string) into a binary file, reading back gives segfault, if I remember correctly.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #651 on: December 20, 2010, 04:59:51 am »

Okay, I fixed the iteration.

It's still not doing anything.  :-\
Logged

Shades

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

Well, trying to print a class containing a string (like a char string or String string) into a binary file, reading back gives segfault, if I remember correctly.

How where you telling it to print? I assume you weren't trying to print the class object directly unless you provided stream operators for it and were doing it that way?

The code just does what you tell it :) nothing more. Java will treat it the same way although there you override the toString() function rather than use stream operators.
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 #653 on: December 20, 2010, 07:44:45 am »

Cat like? I'm not strapping my cat to my pc, if that's what you're getting at.
Cat like the cat command, ie something that spits the contents of the file out in a readable form. Strapping a cat to a your computer might do the trick, if it speaks Huffman, that is :P.
« Last Edit: December 20, 2010, 07:46:59 am by ILikePie »
Logged

Supermikhail

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

Well, trying to print a class containing a string (like a char string or String string) into a binary file, reading back gives segfault, if I remember correctly.

How where you telling it to print? I assume you weren't trying to print the class object directly unless you provided stream operators for it and were doing it that way?

The code just does what you tell it :) nothing more. Java will treat it the same way although there you override the toString() function rather than use stream operators.
Yes, I did, and I did like my C++ book told me (write(char *object, sizeof(object)), or something, I don't want to bother)! But I've encountered a couple of code samples from it that either didn't compile or didn't work as intended... So, why do you have to be so difficult, world?
Cat like? I'm not strapping my cat to my pc, if that's what you're getting at.
Cat like the cat command, ie something that spits the contents of the file out in a readable form. Strapping a cat to a your computer might do the trick, if it speaks Huffman, that is :P.
Hey, how do I tell if my cat speaks Huffman if I don't speak Huffman?
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #655 on: December 20, 2010, 09:54:12 am »

Yes, I did, and I did like my C++ book told me (write(char *object, sizeof(object)), or something, I don't want to bother)! But I've encountered a couple of code samples from it that either didn't compile or didn't work as intended... So, why do you have to be so difficult, world?

Wow, okay I wouldn't have recommended doing that unless you knew what it was doing. If that object had any pointers it would have saved the value of the pointer and not where it points to so once you load it again there is a good chance it would just point to essentially random memory.

If you make sure there was no pointers in the class that should work, although I still wouldn't recommend it. Stream operators are much nicer then you can just do "output << object" and "input >> object" to save and load respectively. There are probably better ways to store data based on what you want to do though.

Your gonna have this issue with Java as well although you might be able to abuse the serialise functions to help you out in that case. Both these languages are pretty simple but only do what you tell them :)
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 #656 on: December 20, 2010, 11:39:18 am »

*Scratches Head*
Is my math right? I'm trying to draw a circle, but all I get are four pixels.
Code: [Select]
public static void circle(int x, int y, int radius, Canvas Canv, RGB Color) {
    final double pi = Math.atan(1)*4;
    for (int theta = 0; theta < 360; theta++) {
        pixel(
          (int)Math.sin(theta*(pi/180) )*radius + x,
          (int)Math.cos(theta*(pi/180) )*radius + y,
          Canv, Color);
    }
}
« Last Edit: December 20, 2010, 11:45:14 am by ILikePie »
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #657 on: December 20, 2010, 11:49:47 am »

Hm. That seems wrong, but for different reasons. How do you know you're going to have place for 360 pixels? Or have 360 pixels to draw your circle in? I think theta step should depend on the radius.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #658 on: December 20, 2010, 12:23:33 pm »

It'll draw certain pixels one on top of the other, at least it did when I used it a year ago for some Cortex Command mod.
But, never mind. I'm using the Bresenham circle algorithm, which works just fine.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #659 on: December 20, 2010, 12:42:09 pm »

Since charstars are pointers to the first element of a char array, does that mean that, for example, char szString[0] = strtok(cInput, " ") would work just as well as char *cString = strtok(cInput, " ")?
Logged
Pages: 1 ... 42 43 [44] 45 46 ... 78