ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i can assign to every member of the structure the correct values i need to.
if in the same functuion i read from the appropriate addresses, i get all correct results. but, as soon as I lave the function, and want to access the char pointer in the struct, I get some messed up characters (8 characters).
if this is no problem, i will give you the link where you can get the package. the error appears in the queue_handler.c file (if you compile the program, you will get appropriate output) in the find_user function.
You were not allocating any space for the strings in your structs. I changed the two char* in your structs to char data[50] and it works. You need to malloc space for the strings that you read in.
Code:
diff -C2 net2_bantumi/Makefile net2_bantumi2/Makefile
*** net2_bantumi/Makefile Sun May 12 12:10:16 2002
--- net2_bantumi2/Makefile Mon Jun 24 10:16:03 2002
***************
*** 2,12 ****
all:
! $(CC) -c client.c
! $(CC) -c server_master.c
! $(CC) -c server_game.c
! $(CC) -c bantumi_common.c
! $(CC) -c queue_handler.c
! $(CC) -o client client.o bantumi_common.o
! $(CC) -o server server_master.o queue_handler.o bantumi_common.o server_game.o
clean:
--- 2,12 ----
all:
! $(CC) -g -c client.c
! $(CC) -g -c server_master.c
! $(CC) -g -c server_game.c
! $(CC) -g -c bantumi_common.c
! $(CC) -g -c queue_handler.c
! $(CC) -g -o client client.o bantumi_common.o
! $(CC) -g -o server server_master.o queue_handler.o bantumi_common.o server_game.o
clean:
***************
*** 16,18 ****
nice:
make all
! rm -f *.o
\ No newline at end of file
--- 16,18 ----
nice:
make all
! rm -f *.o
diff -C2 net2_bantumi/bantumi.h net2_bantumi2/bantumi.h
*** net2_bantumi/bantumi.h Sun Jun 16 19:39:06 2002
--- net2_bantumi2/bantumi.h Mon Jun 24 10:58:16 2002
***************
*** 26,30 ****
typedef struct base
{
! char *secret;
int conn_num;
struct base *next;
--- 26,30 ----
typedef struct base
{
! char secret[50];
int conn_num;
struct base *next;
***************
*** 35,39 ****
int type;
int len;
! char *data;
}packet;
--- 35,39 ----
int type;
int len;
! char data[50];
}packet;
diff -C2 net2_bantumi/bantumi_common.c net2_bantumi2/bantumi_common.c
*** net2_bantumi/bantumi_common.c Fri Jun 21 13:36:33 2002
--- net2_bantumi2/bantumi_common.c Mon Jun 24 10:59:10 2002
***************
*** 109,113 ****
}
while(len>0);
! r_data->data=buffer_helper;
free(buffer);
free(buffer_helper);
--- 109,113 ----
}
while(len>0);
! strncpy( r_data->data,buffer_helper, 49 );
free(buffer);
free(buffer_helper);
Only in net2_bantumi2: client
diff -C2 net2_bantumi/queue_handler.c net2_bantumi2/queue_handler.c
*** net2_bantumi/queue_handler.c Fri Jun 21 18:25:38 2002
--- net2_bantumi2/queue_handler.c Mon Jun 24 10:39:26 2002
***************
*** 8,12 ****
list=(u_elem *)malloc(sizeof(u_elem));
list->conn_num=0;
! list->secret=NULL;
list->next=NULL;
return(list);
--- 8,12 ----
list=(u_elem *)malloc(sizeof(u_elem));
list->conn_num=0;
! strcpy(list->secret,"");
list->next=NULL;
return(list);
***************
*** 22,26 ****
}
new=(u_elem *)calloc(sizeof(u_elem),1);
! new->secret=secret;
new->conn_num=conn_num;
new->next=NULL;
--- 22,26 ----
}
new=(u_elem *)calloc(sizeof(u_elem),1);
! strncpy(new->secret,secret,49);
new->conn_num=conn_num;
new->next=NULL;
Only in net2_bantumi2: server
Output from server.c
Code:
waiting for connection on socket 3
listening on: 4
u_info received containing: type: 3 secret: hello
finding user
new user added: socket: 4 secret: hello
sending: . 0.29.please wait. you are in queue
writing complete
listening on: 5
u_info received containing: type: 3 secret: hello
finding user
comparing hello
to hello
. more info: 4
removing
done.
playing: 4, 5
broadcasting boards contents...
rotating
sending: . 1.29.00404040404040004040404040400
writing complete
rotating
sending: . 1.29.00404040404040004040404040400
writing complete
broadcasting done...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.