Xlib help - Array of Structs

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Xlib help - Array of Structs
# 1  
Old 12-14-2012
Xlib help - Array of Structs

Hey guys!
First of all english is not my main language so sorry for any english mistakes.
Im from Portugal!

1. The problem statement, all variables and given/known data:

Im having a problema creating and array of structs for a work i need to do. (xLib)

2. Relevant commands, code, scripts, algorithms:

So i created a struct, that holds 4 ints:

X = X position
Y = Y postion
dimX = horizontal dimension
dimY = vertical dimension

this 4 ints represent a rectangle.

The struct:

Code:
typedef struct _blocks {
    int X, Y ,dimX, dimY;
} str_blocks;

So now i want to assign values to this int's, but since i dont want just one rectangle i want, for example 3, the best thing to do is to create an array of this struct right?

So for 3 rectangle:

Code:
str_blocks blocks[3];

blocks[0] = {50, 50, 150, 20};
blocks[1] = {200, 50, 150, 20};
blocks[2] = {300, 150, 150, 20};

So this doesnt work and i dont know why. ive been looking in the internet and
saw lots of examples where they declare the values like this, im obviously missing something...

Tried to assign value by value:

Code:
blocks[0].X = 50;
blocks[0].Y = 50;
blocks[0].dimX = 150;
blocks[0].dimy = 20;

blocks[1].X = 200;
blocks[1].Y = 50;
blocks[1].dimX = 150;
blocks[1].dimy = 20;

blocks[2].X = 300;
blocks[2].Y = 150;
blocks[2].dimX = 150;
blocks[2].dimy = 20;

3. The attempts at a solution (include all code and scripts):

I tried to use:

Code:
str_blocks blocks[3];

blocks[0] = {50, 50, 150, 20};
blocks[1] = {200, 50, 150, 20};
blocks[2] = {300, 150, 150, 20};

To give diferent values to the blocks.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Im from Portugal anyway.

ESTG IPVC Portugal - Viana do Castelo
Engenharia da Computação Gráfica e multimédia.
Teacher name: João Raposo
www . estg . ipvc . pt

Last edited by Corona688; 12-14-2012 at 11:44 AM..
# 2  
Old 12-14-2012
Thank you for completely answering the homework template.

Please use code tags, like [code] stuff [/code] to post code. This preserves indentation in your code, makes it clear where code begins and ends, and prevents random things from turning into smilies.

I see a typo in some of your code. dimy vs dimY. Except for that, your 'assign by value' code actually worked -- so I suspect there's something else wrong in code you didn't post. Please post your complete program.

Also, the only time you can assign whole blocks of memory with { ... } is when the variable is being declared -- so you could do this:

Code:
typedef struct _blocks {
    int X, Y ,dimX, dimY;
} str_blocks;

int main()
{
        str_blocks blocks[3]={
                {50, 50, 150, 20},
                {200, 50, 150, 20},
                {300, 150, 150, 20},
        };

}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Xlib registering

hey, Im new to the linux world. Lately, I have tried to create a glx window with xlib, making it a popup window(fullscreen) so I set override_redirect to true. Im happy with the removed borders, but apparantly, the application doesnt show up in the left bar in ubuntu, neither when I press alt... (4 Replies)
Discussion started by: thedardanius
4 Replies

2. Programming

Xlib help - Array of Structs

Hey guys! First of all english is not my main language so sorry for any english mistakes. Second im a total beginner in programming, still i have a school work to do and i found a problem. Probably something easy to solve but it's driving me crazy. So i created a struct, that holds 4 ints: ... (1 Reply)
Discussion started by: Spiritvs
1 Replies

3. UNIX for Advanced & Expert Users

xlib and keyboard events

1. If there's some better place where xlib experts hang out, please tell me. Despite an assiduous search, I could not find an xlib reflector. 2. My actual question: In an xterm, I want to grab and process all keyboard events in a program running inside the xterm. For example, with my program... (5 Replies)
Discussion started by: N7DR
5 Replies

4. Programming

[solved]help passing array of structs to function in c

this is my code to try and prinnt out a deck of cards. the print function worked when used inside main without being a function but now i cant get it to work as a function probably since i dont know how to pass a struct array in c. I gave it a shot but i keep getting an assortment of errors. The... (0 Replies)
Discussion started by: bjhum33
0 Replies

5. UNIX for Dummies Questions & Answers

Xlib Errors

Hi, I am handling user issues in my team. Users have their Unix session running on Citrix MFU. Recently, I was suppose to address a user issue which is as below: Gets the below error when tries to open nedit: Xlib: connection to ":165.0" refused by server Xlib: Client is not... (1 Reply)
Discussion started by: mspatil0037
1 Replies

6. Programming

Xlib simple program.

I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages. I have tried and tried,but never get past Hello World. Can someone help me please? ---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
Discussion started by: megane16v
2 Replies

7. Programming

problems with drawing in x using xlib

Hi all, I'm currently learning xlib and I've encountered a bizarre mistake: function calls such as XDrawPoint, XDrawLine, etc., don't seem to work; a blank window with nothing in is appears. I believe this has something to do with the window manager I use, fluxbox. After checking the code and... (0 Replies)
Discussion started by: hydronium
0 Replies

8. UNIX and Linux Applications

vncserver xlib error

Hello! Im running tight VNC on Red Hat Enterprise Linux 4.0. How can I increase the number of X clients that I can run in a VNC session?I need to run aproximately 500 programs in one VNC session, but at this time I can only 236 -> i've tryed to launch 250 xclock's in background and when it... (0 Replies)
Discussion started by: karpoand
0 Replies

9. UNIX for Advanced & Expert Users

xlib error

Hello! Im running tight VNC on Red Hat Enterprise Linux 4.0. How can I increase the number of X clients that I can run in a VNC session?I need to run aproximately 500 programs in one VNC session, but at this time I can only 236 -> i've tryed to launch 250 xclock's in background and when it... (3 Replies)
Discussion started by: karpoand
3 Replies

10. Programming

pipes + structs

heya got a small problem here. im trying to pipe eg: 'ls | more'. i have created a command line parser which separates ls and more into two commands. i have also created a struct, each struct has a command name, number of arguments, redirect_in, redirect_out, pipe_in, etc etc.... eg: struct... (0 Replies)
Discussion started by: mile1982
0 Replies
Login or Register to Ask a Question