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 ... 59 60 [61] 62 63 ... 78

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

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #900 on: February 12, 2011, 05:05:20 am »

Tried messing around with those nodes just now, the correct syntax is this:
Code: [Select]
...
node a; a.value = 1;
node b; b.value = 0; b.left = &a;
node c; c.value = 0; c.left = &b;
printf("%d\n", c.left->left->value);
...

$ gcc -o nodes nodes.c
$ ./nodes
1

Logged

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #901 on: February 12, 2011, 12:16:58 pm »

That code only works if you're stack allocating your nodes. Which, in practice, you will never do.
Logged

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #902 on: February 12, 2011, 10:47:19 pm »

That code only works if you're stack allocating your nodes. Which, in practice, you will never do.

True, but (aside from the malloc calls) the only change is upgrading the period to an arrow between 'c' and the first 'left' right?
Well... all the other periods... aaand dropping the ampersands on lines 2&3...

Ah, and add a star to the variable type.

So it becomes this
Code: [Select]
...
node* a, b, c;
/* 3 malloc calls */
a->value = 1;
 b->value = 0; b->left = a;
 c->value = 0; c->left = b;
printf("%d\n", c->left->left->value);
...

I think that's it... (still rather new to C, but I think i've got the syntax around pointers figured out)
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #903 on: February 13, 2011, 05:14:01 pm »

One pointer, it's not

Code: [Select]
node* a, b, c;
as that would have an entirely unexpected result. Try

Code: [Select]
node *a, *b, *c;
instead.


Edit: Why not give a full example?

This is only one of the countless ways to interact with a tree structure. This is only an example, so it's not really the qality of code that should be used in an actual project, but it should be sufficient for an example.

Spoiler: Somewhat long example (click to show/hide)
« Last Edit: February 13, 2011, 05:36:37 pm by qwertyuiopas »
Logged
Eh?
Eh!

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #904 on: February 14, 2011, 07:10:38 am »

You can call a struct and the typedeffed type by the same name? Cool, I thought it can mess things up.
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #905 on: February 14, 2011, 07:28:26 am »

actually, in C++, Typedef is redundant, and, as far as I know, mostly ignored.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #906 on: February 14, 2011, 08:34:32 am »

actually, in C++, Typedef is redundant, and, as far as I know, mostly ignored.
Ignoring it would be madness, but yes, it is redundant. But qwerty is doing C (as you can see by the mallocs), where it is necessary.
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))

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #907 on: February 14, 2011, 08:44:19 am »

actually, in C++, Typedef is redundant, and, as far as I know, mostly ignored.
C doesn't have any of those fancy OOP features you get with C++.
Logged

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #908 on: February 14, 2011, 09:13:55 am »

*removed due to potential programming language war*
Sorry
« Last Edit: February 14, 2011, 09:21:28 am by TolyK »
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #909 on: February 14, 2011, 09:19:16 am »

*removed due to potential programming language war* ;)
Don't even joke about that. We try to keep the language/compiler/platform wars to a minimum.
« Last Edit: February 14, 2011, 02:08:59 pm by Siquo »
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))

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #910 on: February 14, 2011, 09:20:19 am »

***
Don't even joke about that. We try to keep the language/compiler/platform wars to a minimum.
sure thing.
« Last Edit: February 14, 2011, 11:39:49 am by TolyK »
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

IHateOutside

  • Bay Watcher
  • Fire safety is for wimps.
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #911 on: February 14, 2011, 11:35:18 am »

You may want to remove the post in quotes as well.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #912 on: February 16, 2011, 11:22:46 am »

I've been learning the basics of Java just out of interest. This is giving me some problems.

Spoiler (click to show/hide)

Theres some problem with the main method. any ideas?

Exact error message:
java.lang.NoSuchMethodError: main
Exception in thread "main"
« Last Edit: February 16, 2011, 11:24:58 am by Deadmeat1471 »
Logged

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #913 on: February 16, 2011, 11:25:05 am »

^ Sorry I can't help, I know java as much as the back of my head.
*****
In other news:
What do you think of this?
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #914 on: February 16, 2011, 11:26:46 am »

That looks pretty epic.
Logged
Pages: 1 ... 59 60 [61] 62 63 ... 78