Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 283 284 [285] 286 287 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 882584 times)

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4260 on: March 20, 2013, 02:35:57 pm »

Yes. Please explain. Me no understando.
Throwing balls at eachother is a common american pastime, and apparently expected of fathers to do with their sons. As it builds character. However, that is usually already a primitive type. Jokes sound really stupid when you have to explain them.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4261 on: March 20, 2013, 02:42:33 pm »

Yes. Please explain. Me no understando.
Throwing balls at eachother is a common american pastime, and apparently expected of fathers to do with their sons.
I see what you did there.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4262 on: March 20, 2013, 02:52:24 pm »

... oh no I did not.

Damnit.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4263 on: March 20, 2013, 02:53:21 pm »

... oh no I did not.

Damnit.
Oh. Wait, no, that's not what I meant at all D:
Logged

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4264 on: March 20, 2013, 03:15:50 pm »

Yes. Please explain. Me no understando.

The main code, starting at "public static void main(String[] args){" creates two new instances of the object P, called "parent" and "child". Object P is defined to have an attribute "target", which is another object P. The child's target is set to be the parent, and the parent's target is set to be the child. The parent's "aim" function is called, with a new Ball object as the parameter. The Ball has no attributes or functions, but extends the Throwable class, making Balls the same type of thing as Java Exceptions.

The P.aim(Ball B) function has a try-catch block, where the only thing done inside the try part is to throw a Ball, specifically the Ball that P.aim took as a parameter. Since a Throwable was thrown, the catch block is triggered, and calls the aim function of the P that is the current P's target.

So, you get the parent and child recursively tossing balls around ad infinitum.

It's basically a really convoluted pun.
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4265 on: March 20, 2013, 03:30:04 pm »

Thanks.

That's absolutely hilarious.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4266 on: March 20, 2013, 06:18:04 pm »

Speaking of XKCD and programming, this got a good laugh out of me.

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4267 on: March 21, 2013, 09:40:31 pm »

C again :P

This time we read from a source file, count the number of letters, numbers, other characters, total them all, and print the counts. We've been told to use ctype.h (despite not being used in this chapter AT ALL) to determine which category each character falls in to.

Problem is when I try to run the program, I get insanely high counts that cannot be accurate (also the data isn't transferring between functions properly, but one step at a time). Take a look-see and point out my error(s)?
Spoiler (click to show/hide)
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4268 on: March 21, 2013, 09:51:15 pm »

When you say you get insanely high counts that cannot be accurate, can you show us a test file and the results you get from running the program on this file?
Logged

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4269 on: March 21, 2013, 09:54:58 pm »

Spoiler: Source file (click to show/hide)
Spoiler: Output (click to show/hide)
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4270 on: March 21, 2013, 09:58:29 pm »

It's pretty obvious now. Incrementing a pointer-to-int does something different to incrementing an int, and you were incrementing the pointers and not the variables that they were pointing to. I think you can do something like *l++ to do this (or maybe (*l)++).
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4271 on: March 21, 2013, 09:59:36 pm »

Isn't & the dereference operator?

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4272 on: March 21, 2013, 10:02:27 pm »

It's pretty obvious now. Incrementing a pointer-to-int does something different to incrementing an int, and you were incrementing the pointers and not the variables that they were pointing to. I think you can do something like *l++ to do this (or maybe (*l)++).
That did it! It was actually this
(*l)++;
What's better, the numbers are now passing correctly to the print function. Thanks a lot!

Isn't & the dereference operator?
I did try that at first, but it didn't help :(
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4273 on: March 21, 2013, 10:51:06 pm »

Isn't & the dereference operator?

& gets the memory address of a variable. It is also used to pass things by reference (which is generally easier than using pointers). For example:

Code: [Select]
int i = 5;
int *j = &i; // Pointer to i

[/code]
void DoSomething(int &i){
  i = 5;
}
int main(){

}
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4274 on: March 21, 2013, 11:00:28 pm »

Isn't & the dereference operator?

* is the dereference operator (-> also works for calling member functions on struct/class pointers). & gets the memory address of a variable (sort of the opposite of the dereference operator). It is also used to pass things by reference (which is generally easier than using pointers). For example:

Code: [Select]
int main(){
  int i = 5;
  int *q = &i; // Pointer to i
  cout << (*q) << endl; // prints 5;
}

Code: [Select]
void DoSomething(int &i){
  i = 5;
}
int main(){
  int variable = 12;
  DoSomething(variable);
  cout << variable << endl; //outputs 5
  return 0;
}

it can also be used to create variables that function similarly to pointers with reduced errors. (you dont have to dereference them or worry about segaults, but you cant perform pointer arithmetic on them):
Code: [Select]
int main(){
  int var = 55;
  int &morevar = var;
  morevar = 10;
  cout << var << endl // prints 10
}
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!
Pages: 1 ... 283 284 [285] 286 287 ... 796