• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 05:19
CET 11:19
KST 19:19
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets0$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)12Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822
StarCraft 2
General
SC2 Spotted on the EWC 2026 list? Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns Spontaneous hotkey change zerg Chinese SC2 server to reopen; live all-star event in Hangzhou
Tourneys
$25,000 Streamerzone StarCraft Pro Series announced $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
Potential ASL qualifier breakthroughs? BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest Data analysis on 70 million replays
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Beyond All Reason Nintendo Switch Thread Awesome Games Done Quick 2026! Mechabellum Stormgate/Frost Giant Megathread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1224 users

The Big Programming Thread - Page 56

Forum Index > General Forum
Post a Reply
Prev 1 54 55 56 57 58 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
May 25 2011 05:38 GMT
#1101
On May 25 2011 09:23 mr_tolkien wrote:
I need help :/ I have some troubles with data structures in Java, and there is something I don't get.

Here is a piece of code from me :
+ Show Spoiler +
HashMap<Position, PositionTree> sons = new HashMap<Position, PositionTree>();

Position a = new Position(0,0);
sons.put(a, null);
Position b = new Position(0,0);
System.out.println(sons.keySet().contains(a));
System.out.println(b.equals(a));
System.out.println(sons.keySet().contains(b));

Position is just a standard class, PositionTree is my tree structure.
When running this I get true true false.
Meaning b.equals(a) is true, sons.keySet() contains a, but... sons.keySet() doesn't "contain" b ?

When looking at the doc of contains ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Set.html#contains(java.lang.Object) ) it says «returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). »
It seems to me like it should return true... Does anybody have any clue on what I am doing wrong ?


I agree, the documentation suggests that it should return true.

I think a good start would be to override the default equals() implementation in the Position class with your own implementation and see if that works and if it even gets triggered. It looks to me as if it is not using the correct equals() method for some reason.
One Student
Profile Joined April 2011
73 Posts
Last Edited: 2011-05-25 05:41:00
May 25 2011 05:40 GMT
#1102
On May 25 2011 09:23 mr_tolkien wrote:
I need help :/ I have some troubles with data structures in Java, and there is something I don't get.

Here is a piece of code from me :
+ Show Spoiler +
HashMap<Position, PositionTree> sons = new HashMap<Position, PositionTree>();

Position a = new Position(0,0);
sons.put(a, null);
Position b = new Position(0,0);
System.out.println(sons.keySet().contains(a));
System.out.println(b.equals(a));
System.out.println(sons.keySet().contains(b));

Position is just a standard class, PositionTree is my tree structure.
When running this I get true true false.
Meaning b.equals(a) is true, sons.keySet() contains a, but... sons.keySet() doesn't "contain" b ?

When looking at the doc of contains ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Set.html#contains(java.lang.Object) ) it says «returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). »
It seems to me like it should return true... Does anybody have any clue on what I am doing wrong ?


I think the problem is with your equals() method. Check to see if you have correctly overwritten the Object class's equals method:

public boolean equals(Object obj){}

Using another equals(Position o) method will not suffice since the contains method will most likely use the Object class's equals method. So try that and do the necessary casting and see if it works.

EDIT: sorry guy above me I didn't see your post in time. ;p
Depression is what you get for leading a repetitive life.
Cambium
Profile Blog Joined June 2004
United States16368 Posts
Last Edited: 2011-05-25 05:49:08
May 25 2011 05:45 GMT
#1103
On May 25 2011 14:40 One Student wrote:
Show nested quote +
On May 25 2011 09:23 mr_tolkien wrote:
I need help :/ I have some troubles with data structures in Java, and there is something I don't get.

Here is a piece of code from me :
+ Show Spoiler +
HashMap<Position, PositionTree> sons = new HashMap<Position, PositionTree>();

Position a = new Position(0,0);
sons.put(a, null);
Position b = new Position(0,0);
System.out.println(sons.keySet().contains(a));
System.out.println(b.equals(a));
System.out.println(sons.keySet().contains(b));

Position is just a standard class, PositionTree is my tree structure.
When running this I get true true false.
Meaning b.equals(a) is true, sons.keySet() contains a, but... sons.keySet() doesn't "contain" b ?

When looking at the doc of contains ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Set.html#contains(java.lang.Object) ) it says «returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). »
It seems to me like it should return true... Does anybody have any clue on what I am doing wrong ?


I think the problem is with your equals() method. Check to see if you have correctly overwritten the Object class's equals method:

public boolean equals(Object obj){}

Using another equals(Position o) method will not suffice since the contains method will most likely use the Object class's equals method. So try that and do the necessary casting and see if it works.

EDIT: sorry guy above me I didn't see your post in time. ;p



did you override the default equals/hashCode? You must...

it'd help if you post your Position class

also, instead of getting the keyset, you can call

sons.containsKey( a );
When you want something, all the universe conspires in helping you to achieve it.
EpiK
Profile Blog Joined January 2007
Korea (South)5757 Posts
Last Edited: 2011-05-25 05:49:58
May 25 2011 05:45 GMT
#1104
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.
mr_tolkien
Profile Blog Joined June 2010
France8631 Posts
Last Edited: 2011-05-25 08:43:18
May 25 2011 08:40 GMT
#1105
Thank you for your answers, here is my equals function in Position :
+ Show Spoiler +
public boolean equals(Object o){
if(((Position)o).getX()==this.x && ((Position)o).getY()==this.y)
return true;
return false;
}

Seems to me like it's well coded.

I know of containsKey() btw, but the documentation isn't as clear as contains() for a Set, so for testing purposes I'm doing it with keySet.contains(). I'll change it once I'll sort this out.

EDIT : just figured it out ! I needed to cast b as an Object in my third line... Seems weird because there is no equals(Position) anyway, I was figuring he used the good one.
The legend of Darien lives on
ibutoss
Profile Blog Joined June 2005
Australia341 Posts
May 25 2011 09:02 GMT
#1106
On May 25 2011 14:45 EpiK wrote:
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.


I'd have to disagree. Freelance web development is great for small business, hobby sites & new start ups. However there is a limit to the size of these projects due to the nature of small teams so big business will still require established IT services or have their own in-house development teams.
Nada got Yooned
mr_tolkien
Profile Blog Joined June 2010
France8631 Posts
Last Edited: 2011-05-25 09:17:35
May 25 2011 09:12 GMT
#1107
I'm back again, it was a wrong test I did, it still doesn't work the slightest \o/

I even did this :
sons.keySet().toArray()[0].equals(b)
Which returns TRUE.
And still, sons.containsKey(b) returns false.

I'm a bit in «WTFUUUUUUUUUUUUUUUUUUUUUUUUUUUU» mode right now, what I'm doing seems perfectly legit.

PS : I have a workaround working, but I'd like to know why it doesn't work in the first time.
The legend of Darien lives on
sdfno
Profile Joined March 2003
9 Posts
May 25 2011 10:13 GMT
#1108
I am guessin it's because you have overriden equals but not hashCode in your position class.
This means that Object.hashCode is used which explains why the first test is OK, but not the last one.

Here is an example of equals and hashCode for the Position Class:

+ Show Spoiler +

public class Main {
public static void main(String[] args) {

final HashSet<Position> positions = new HashSet<Position>();

final Position a = new Position(0, 0);
final Position b = new Position(0, 0);
positions.add(a);

System.out.println(positions.contains(a));
System.out.println(positions.contains(b));
}
}

class Position {
private int x;
private int y;

Position(int x, int y) {
this.x = x;
this.y = y;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Position position = (Position) o;

if (x != position.x) return false;
if (y != position.y) return false;

return true;
}

@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
}

Tobberoth
Profile Joined August 2010
Sweden6375 Posts
May 25 2011 10:26 GMT
#1109
On May 25 2011 18:02 ibutoss wrote:
Show nested quote +
On May 25 2011 14:45 EpiK wrote:
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.


I'd have to disagree. Freelance web development is great for small business, hobby sites & new start ups. However there is a limit to the size of these projects due to the nature of small teams so big business will still require established IT services or have their own in-house development teams.

I think it depends on the project. I work as a consultant to a very big swedish company on one of their web systems and there's no way a project like this would be done by freelancers since the system is huge and needs constant ongoing development, not only on the actual ASP.NET site but all the extra components, the databases and so on.

However, big companies generally have a lot of projects with very different scopes, I'm sure smaller ones could be done by freelancing smaller teams.
Seldon
Profile Joined March 2011
90 Posts
Last Edited: 2011-05-25 10:53:07
May 25 2011 10:51 GMT
#1110
On May 25 2011 18:02 ibutoss wrote:
Show nested quote +
On May 25 2011 14:45 EpiK wrote:
just curious but are any of you freelance web designers/developers? If so, what are your thoughts on the future demand of freelance web work? I've come across some really interesting articles (here's a good one for those who are interested) and the general consensus seems to be that more businesses/clients are going to realize that hiring freelancers is way cheaper so demand's going to increase. That's probably a really shallow prediction so I was curious as to what you guys thought.


I'd have to disagree. Freelance web development is great for small business, hobby sites & new start ups. However there is a limit to the size of these projects due to the nature of small teams so big business will still require established IT services or have their own in-house development teams.


I agree if we are talking of a country like America (I don't know how Australia is in this regard). However I would like to add that if we are talking of Europe or a country with a worker-friendly labor code the situation is more in favor of freelancers. I see you are in Korea and I'm not sure what the situation is there but I'm under impression that it's more similar to Europe than to America.

In Europe in general it's getting really expensive to hire somebody due to social security, indemnifications you have to pay fired employees, the fact that if an employee gets pregnant you have to pay her while she takes a leave, the amount of bureaucratic BS that comes with employing every person, etc. Now I'm not saying this is good or bad, but it is a fact that it makes hiring more expensive and riskier.

Because of this contracting freelancers is incredibly attractive at the moment. You just pay for the work and none of the overheads cited above and if they don't deliver in time the contract is void and you don't have to pay. If an employee doesn't deliver in time... you are screwed and he isn't gonna return his paychecks.

So yeah, if what I explained above is true of the country you are in, I would say don't be afraid to go freelancer.
TheGiz
Profile Blog Joined October 2010
Canada708 Posts
Last Edited: 2011-05-25 18:17:33
May 25 2011 18:09 GMT
#1111
Hey, does anyone in this thread have experience with Excel?

I'm currently working on a super-huge Excel program at work (roughly 50-60 sheets and 20 modules) and I'm having some trouble with buttons. In a new workbook I am able to make a button and right-click on it to view its properties (i.e. Visible, Name, Caption, Background Colour, etc.). In the program though when I right-click to view the button's properties, I can't see the properties of the button I've selected - the Properties window is just blank. If I make a new button in the program the same thing happens.

Any idea what setting may have disabled my ability to view these properties?

EDIT: It just worked. Don't ask me how but it did. I'll edit this again if it keeps giving me problems.
Life is not about making due with what you have; it's about finding out just how much you can achieve. Never settle for anything less than the best. - - - Read my blog!
Cambium
Profile Blog Joined June 2004
United States16368 Posts
Last Edited: 2011-05-25 18:16:34
May 25 2011 18:15 GMT
#1112
On May 25 2011 17:40 mr_tolkien wrote:
Thank you for your answers, here is my equals function in Position :
+ Show Spoiler +
public boolean equals(Object o){
if(((Position)o).getX()==this.x && ((Position)o).getY()==this.y)
return true;
return false;
}

Seems to me like it's well coded.

I know of containsKey() btw, but the documentation isn't as clear as contains() for a Set, so for testing purposes I'm doing it with keySet.contains(). I'll change it once I'll sort this out.

EDIT : just figured it out ! I needed to cast b as an Object in my third line... Seems weird because there is no equals(Position) anyway, I was figuring he used the good one.


what about hashcode

it's not enough to only override equals

From a very high level, how a hashmap works is that
1) converts key object to number (this is what hashCode does)
2) put the value object in an array, position determined by the number obtained in 1.

You do not need to perform a cast when you call .equals(...), all objects in Java has the Object base class, so you can pass in Position objects just fine.

Also, your equals method is badly coded, you should use the .equals(...) that comes with your IDE and make modifications as you see fit.

For example, you don't check for null explicitly, and your .equals will throw an NPE if a null is passed in.
When you want something, all the universe conspires in helping you to achieve it.
Manit0u
Profile Blog Joined August 2004
Poland17596 Posts
Last Edited: 2011-05-28 10:52:25
May 28 2011 10:32 GMT
#1113
Anyone here with GTK+ experience?

I've just started my adventure with it and I'm trying to figure out the basics but run into some problems already...

+ Show Spoiler [code] +


#include <gtk/gtk.h>
#include <stdlib.h>

#define STARTING_STAT 8;
#define STARTING_POOL 25;

char StatBuffer[5];

struct StatsConfig
{
gint8 StatStr;
gint8 StatDex;
gint8 StatCon;
gint8 StatInt;
gint8 StatWis;
gint8 StatCha;
gint8 StatPool;
};

struct StatsConfig* GetConfig();
int PoolIncrease(struct StatsConfig *config);
int PoolDecrease(struct StatsConfig *config);
int StrIncrease(struct StatsConfig *config);
int StrDecrease(struct StatsConfig *config);
void StrIncreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config);
void StrDecreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config);
void ReleaseMemory(struct StatsConfig *config);

int main(int argc, char** argv)
{
GtkWidget *window;
GtkWidget *frame;
GtkWidget *strPlusButton;
GtkWidget *strMinusButton;
GtkWidget *strLabel;
GtkWidget *poolLabel;
struct StatsConfig *config;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
frame = gtk_fixed_new();
strPlusButton = gtk_button_new_with_label("+");
strMinusButton = gtk_button_new_with_label("-");
strLabel = gtk_label_new("8");
poolLabel = gtk_label_new("25");
poolText = gtk_label_new("Stat point pool:");
strText = gtk_label_new("Str:");
config = GetConfig();

gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_title(GTK_WINDOW(window), "test");

gtk_container_add(GTK_CONTAINER(window), frame);

gtk_widget_set_size_request(strPlusButton, 25, 15);
gtk_fixed_put(GTK_FIXED(frame), strPlusButton, 5, 42);

gtk_widget_set_size_request(strMinusButton, 25, 15);
gtk_fixed_put(GTK_FIXED(frame), strMinusButton, 85, 42);

gtk_fixed_put(GTK_FIXED(frame), strLabel, 70, 40);
gtk_fixed_put(GTK_FIXED(frame), strText, 42, 40);

gtk_fixed_put(GTK_FIXED(frame), poolLabel, 200, 10);
gtk_fixed_put(GTK_FIXED(frame), poolText, 92, 10);

gtk_widget_show_all(window);

g_signal_connect(strPlusButton, "clicked",
G_CALLBACK(StrIncreaseButtonAction), strLabel);

g_signal_connect(strMinusButton, "clicked",
G_CALLBACK(StrDecreaseButtonAction), strLabel);

g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_main();

ReleaseMemory(config);

return 0;
}

struct StatsConfig* GetConfig()
{
gint8 statStr, statDex, statCon, statInt, statWis, statCha = STARTING_STAT;
gint8 statPool = STARTING_POOL;

struct StatsConfig *config;
config = malloc(sizeof(struct StatsConfig));

config->StatStr = statStr;
config->StatDex = statDex;
config->StatCon = statCon;
config->StatInt = statInt;
config->StatWis = statWis;
config->StatCha = statCha;
config->StatPool = statPool;

return config;
}

int PoolIncrease(struct StatsConfig *config)
{
return config->StatPool +1;
}

int PoolDecrease(struct StatsConfig *config)
{
gint8 statPool = config->StatPool;

if(statPool > 0)
{
return config->StatPool -1;
}

return config->StatPool;
}

int StrIncrease(struct StatsConfig *config)
{
gint8 statPool = config->StatPool;

if(statPool > 0)
{
PoolDecrease(config);

return config->StatStr +1;
}

return config->StatStr;
}

int StrDecrease(struct StatsConfig *config)
{
gint8 statStr = config->StatStr;

if(statStr > 3)
{
PoolIncrease(config);

return config->StatStr -1;
}

return config->StatStr;
}

void StrIncreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config)
{
StrIncrease(config);

sprintf(StatBuffer, "%d", config->StatStr);
gtk_label_set_text(strLabel, StatBuffer);

// sprintf(StatBuffer, "%d", config->StatPool);
// gtk_label_set_text(poolLabel, StatBuffer);
}

void StrDecreaseButtonAction(GtkWidget *widget, gpointer strLabel, struct StatsConfig *config)
{
StrDecrease(config);

sprintf(StatBuffer, "%d", config->StatStr);
gtk_label_set_text(strLabel, StatBuffer);
}

void ReleaseMemory(struct StatsConfig *config)
{
if (config != NULL)
{
free(config);
config = NULL;
}
}



As you can see, I'm trying to create a simple window that will emulate the D20 system for RPG's. Right now it compiles and runs but pressing the button results in seg fault

For now I've just created 2 buttons just to test things out. I have no idea how to make one button change two labels at the same time too, when I tried to pass more arguments to the action it didn't want to work

Any tips?

P. S.
Don't look at the atrocious button/label placement, I put it there randomly just to test things out.
Time is precious. Waste it wisely.
razzloss
Profile Joined October 2010
Finland4 Posts
Last Edited: 2011-05-28 12:56:55
May 28 2011 12:52 GMT
#1114
On May 28 2011 19:32 Manit0u wrote:
As you can see, I'm trying to create a simple window that will emulate the D20 system for RPG's. Right now it compiles and runs but pressing the button results in seg fault

Yes, I bet it does. In g_signal_connect you are passing a gtk_label as the data parameter for the signal handler, but in the handler itself you're trying to use the label as a struct StatsConfig*. Which obviously leads to problems. edit: Sorry read that wrong. It seems that the strlabel is used correctly in the signal handler. The problem is that the struct StatsConfig* probably contains garbage data as it isn't filled correctly.


For now I've just created 2 buttons just to test things out. I have no idea how to make one button change two labels at the same time too, when I tried to pass more arguments to the action it didn't want to work

You can only pass one 'own' parameter to the handler. So if you want to change two or more labels in the same handler, you have to put them in to a struct/linked list/table and pass a pointer to that to the signal handler.



P. S.
Don't look at the atrocious button/label placement, I put it there randomly just to test things out.

You shouldn't use gtk_fixed for anything. Instead use the other containers, (e.g. vbox/hbox) which place themselves automatically and react correctly to theme/window size changes.


thedeadhaji *
Profile Blog Joined January 2006
39489 Posts
May 28 2011 15:11 GMT
#1115
Couldn't really figure out how to properly set up the Google ap environment, so I decided to just set up a proper python environment and learn the language and get used to coding again before heading onto interface type stuff

Wish me luck!
jsmith
Profile Joined January 2011
United States18 Posts
May 28 2011 16:23 GMT
#1116
Hey guys I was wondering if anyone cold help me out with this question. I just graduated with my computer science degree the job I been at for a few months doesn't use my degree to much. I pretty much write SQL and do some database stuff. I wanna be able to stay fresh with other programming because I plan on either getting into the programming side of things with my company or move to another company that's more programming oriented. So, what would you guys suggest I do for some sort of recreational programming to help keep it fresh in my mind? Thanks!
Manit0u
Profile Blog Joined August 2004
Poland17596 Posts
Last Edited: 2011-05-28 17:42:43
May 28 2011 17:34 GMT
#1117
On May 28 2011 21:52 razzloss wrote:
Show nested quote +
On May 28 2011 19:32 Manit0u wrote:
As you can see, I'm trying to create a simple window that will emulate the D20 system for RPG's. Right now it compiles and runs but pressing the button results in seg fault

Yes, I bet it does. In g_signal_connect you are passing a gtk_label as the data parameter for the signal handler, but in the handler itself you're trying to use the label as a struct StatsConfig*. Which obviously leads to problems. edit: Sorry read that wrong. It seems that the strlabel is used correctly in the signal handler. The problem is that the struct StatsConfig* probably contains garbage data as it isn't filled correctly.

Show nested quote +

For now I've just created 2 buttons just to test things out. I have no idea how to make one button change two labels at the same time too, when I tried to pass more arguments to the action it didn't want to work

You can only pass one 'own' parameter to the handler. So if you want to change two or more labels in the same handler, you have to put them in to a struct/linked list/table and pass a pointer to that to the signal handler.


Show nested quote +

P. S.
Don't look at the atrocious button/label placement, I put it there randomly just to test things out.

You shouldn't use gtk_fixed for anything. Instead use the other containers, (e.g. vbox/hbox) which place themselves automatically and react correctly to theme/window size changes.




Thanks for the info. I've decided to scrap this thing allogether and write it from scratch, which led me to a ton of new problems...
I've decided to leave the buttons and operations on values for later and focused on getting my initial text to display in some more coherent way.

+ Show Spoiler [code] +


#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>

#define STARTING_STAT 8;
#define STARTING_POOL 25;

struct StatsConfig
{
gint8 StatStr;
gint8 StatDex;
gint8 StatCon;
gint8 StatInt;
gint8 StatWis;
gint8 StatCha;
gint8 StatPool;
};

char buffer[2];
struct StatsConfig* GetConfig();
char* ReturnStatPool(struct StatsConfig *config);
char* ReturnStats(struct StatsConfig *config);
char* ReturnStatNames();
void ReleaseMemory(struct StatsConfig *config);

int main(int argc, char** argv)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *label;
char *currentStats;
char *currentStatPool;
char *statNames;
struct StatsConfig *config;

config = GetConfig();
currentStatPool = ReturnStatPool(config);
statNames = ReturnStatNames();
currentStats = ReturnStats(config);

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_title(GTK_WINDOW(window), "Star Wars character builder");
gtk_container_set_border_width(GTK_CONTAINER(window), 5);

hbox = gtk_hbox_new(FALSE, 1);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);

frame = gtk_frame_new("Stat point pool:");
label = gtk_label_new(currentStatPool);
gtk_container_add(GTK_CONTAINER(frame), label);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

hbox = gtk_hbox_new(FALSE, 1);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(window), hbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);

frame = gtk_frame_new("Name:");
label = gtk_label_new(statNames);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_container_add(GTK_CONTAINER(frame), label);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

frame = gtk_frame_new("Value:");
label = gtk_label_new(currentStats);
gtk_container_add(GTK_CONTAINER(frame), label);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);

gtk_main();

ReleaseMemory(config);

return 0;
}

struct StatsConfig* GetConfig()
{
gint8 statStr, statDex, statCon, statInt, statWis, statCha = STARTING_STAT;
gint8 statPool = STARTING_POOL;

struct StatsConfig *config;
config = malloc(sizeof(struct StatsConfig));

config->StatStr = statStr;
config->StatDex = statDex;
config->StatCon = statCon;
config->StatInt = statInt;
config->StatWis = statWis;
config->StatCha = statCha;
config->StatPool = statPool;

return config;
}

char* ReturnStatPool(struct StatsConfig *config)
{
int statPool = config->StatPool;

sprintf(buffer, "%d", statPool);

return buffer;
}

char* ReturnStats(struct StatsConfig *config)
{
int statStr = config->StatStr;
int statDex = config->StatDex;
int statCon = config->StatCon;
int statInt = config->StatInt;
int statWis = config->StatWis;
int statCha = config->StatCha;

char st1[50];
char st2[2];
char st3[2];
char st4[2];
char st5[2];
char st6[2];
char n = "\n";

sprintf(st1, "%d", statStr);
sprintf(st2, "%d", statDex);
sprintf(st3, "%d", statCon);
sprintf(st4, "%d", statInt);
sprintf(st5, "%d", statWis);
sprintf(st6, "%d", statCha);

strcat(st1, st2);
strcat(st1, n);
strcat(st1, st3);
strcat(st1, n);
strcat(st1, st4);
strcat(st1, n);
strcat(st1, st5);
strcat(st1, n);
strcat(st1, st6);

char* stats = st1;

return stats;
}


char* ReturnStatNames()
{
char* stats = "Strength\nDexterity\nConstitution\nIntelligence\nWisdom\nCharisma\n";

return stats;
}

void ReleaseMemory(struct StatsConfig *config)
{
if (config != NULL)
{
free(config);
config = NULL;
}
}



It was compiling and working fine up until I decided to add the stat values. The problem I'm facing (which is obvious from the code I believe) is that I have absolutely no idea how to make a concatenated string as a char array...

Here's an example of the problem I'm facing:

krs@chameleon:~/workspace/Gtk> gcc -std=c99 -o test test.c `pkg-config --libs --cflags gtk+-2.0`
test.c: In function ‘ReturnStats’:
test.c:132:11: warning: initialization makes integer from pointer without a cast
test.c:142:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
test.c:144:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
test.c:146:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
test.c:148:2: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
/usr/include/string.h:135:14: note: expected ‘const char * restrict’ but argument is of type ‘char’


Internet was no help to me so far
Time is precious. Waste it wisely.
kuresuti
Profile Blog Joined December 2009
1393 Posts
May 30 2011 11:05 GMT
#1118
On May 29 2011 02:34 Manit0u wrote:It was compiling and working fine up until I decided to add the stat values. The problem I'm facing (which is obvious from the code I believe) is that I have absolutely no idea how to make a concatenated string as a char array...


You could try making the string and converting it to a char array like so:


string a = "asd";

char* b = a.c_str();


Not sure if that's what you're asking for though

Good luck!


Tili_us
Profile Joined July 2010
Belgium44 Posts
May 30 2011 11:09 GMT
#1119
Hey guys, I love C++, but I can't ignore the handy stuff that C# gives.

Is there stuff like reflection c++? (maybe in the new version?)

Also, I've being working with Unity3D, and they use Coroutines using the yield command. Is this available in normal C# too ? (or even c++?)
Manit0u
Profile Blog Joined August 2004
Poland17596 Posts
Last Edited: 2011-05-30 15:16:56
May 30 2011 15:12 GMT
#1120
On May 29 2011 00:11 thedeadhaji wrote:
Couldn't really figure out how to properly set up the Google ap environment, so I decided to just set up a proper python environment and learn the language and get used to coding again before heading onto interface type stuff

Wish me luck!


That for web development?

I'm currently trying to get into this: http://www.symfony-project.org/

If you look for Python then go with Django: https://www.djangoproject.com/

P. S.

Disregard my previous post. After looking around I've decided to screw the C/Gtk+ for creating stuff with GUI and opted to go with C++/Qt instead. Gtk widget tree is such a bitch...
Time is precious. Waste it wisely.
Prev 1 54 55 56 57 58 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 41m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 100
StarCraft: Brood War
Sea 4654
Rain 1528
Shuttle 757
Horang2 729
Larva 446
Mini 414
Hyuk 372
Stork 336
actioN 282
Leta 251
[ Show more ]
ZerO 245
Mong 185
EffOrt 137
Soma 137
Zeus 131
Nal_rA 103
Hyun 94
Rush 82
Killer 75
910 68
ggaemo 64
JulyZerg 54
hero 45
Sharp 43
Mind 36
zelot 27
Light 20
Free 20
scan(afreeca) 20
Sexy 19
soO 16
Terrorterran 14
ajuk12(nOOB) 13
Bale 12
Sacsri 12
Noble 10
Dota 2
XcaliburYe104
NeuroSwarm92
ODPixel85
League of Legends
C9.Mang0461
JimRising 460
Counter-Strike
olofmeister1581
shoxiejesuss1019
allub253
Super Smash Bros
Mew2King95
Other Games
summit1g8045
ceh9561
Pyrionflax245
Fuzer 154
ZerO(Twitch)12
Organizations
Other Games
gamesdonequick2922
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2149
• Lourlo1211
• Stunt522
Upcoming Events
WardiTV Invitational
1h 41m
PiGosaur Cup
14h 41m
WardiTV Invitational
1d 1h
The PondCast
1d 23h
OSC
2 days
OSC
3 days
All Star Teams
3 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
4 days
All Star Teams
4 days
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
4 days
[ Show More ]
OSC
5 days
Replay Cast
5 days
Wardi Open
6 days
Liquipedia Results

Completed

Proleague 2026-01-12
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.