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.
/* Reads the incoming line from a socket and try's to split it correct*/
void GetLine(char *line, int servfd) {
/* line = A line WITHOUT `\n` */
int i, rawnr;
char p0[200], p1[200];
char tmp[512], part[512];
if (line[0]!='\0') {
trim(line);
Split(line,' ',0,p0);
Split(line,' ',1,p1);
/*if (strncasecmp(p1,"G",strlen("G"))!=0)*/
printf("%s<--\n",line);
printf("p0: %s - p1: >%s<\n",p0,p1);
if (!strncasecmp(p1,"EB",strlen("EB"))) { /* End of Burst */
printf("Got EB!!\n");
Tok_EA(servfd);
if (joined==FALSE) {
/*sprintf (tmp, "JOIN %s\r\n", HOMECHAN);
SendLine(tmp, TRUE, servfd);
joined=TRUE;*/
}
}
}
}
Output: AB N AliTriX 1 1068972084 wer alitrix.homelinux.net +oiwg B]AAAB ABAAB :Ali<--
p0: AB - p1: >N<
AB N blaat 1 1068972106 wer alitrix.homelinux.net +iw B]AAAB ABAAC :Ali<--
p0: AB - p1: >N<
AB N AliTriX_ 1 1068972109 wer alitrix.homelinux.net +iw B]AAAB ABAAD :Ali<--
p0: AB - p1: >N<
AB B #vodkaz 1068971831 APAAA<--
p0: AB - p1: >B<
AB B #suikode 1068971831 APAAA<--
p0: AB - p1: >B<
AB B #feds 1068971820 ABAAD,ABAAC,ABAAB,APAAA,ABAAA<--
p0: AB - p1: >B<
AB B #coder-com 1068971818 +l 12 ABAAB,APAAA,ABAAA<--
p0: AB - p1: >B<
AB EB <--
p0: AB - p1: >EB<
AB EA <--
p0: AB - p1: >EA<
APAAA R u :AX<--
p0: APAAA - p1: >R<
AB G !1068994838.36479 go.moo.oh.yes.they.do 1068994838.36479<--
p0: AB - p1: >G<
AB SQ alitrix.homelinux.net 0 :Ping timeout<--
p0: AB - p1: >SQ<
There is something else wrong.
I can't directly test your code, because you refer to functions not defined (trim and Split),
but my own testcase (as close to yours as possible):
Code:
#include <string.h>
#include <stdio.h>
void GetLine(char *line, int servfd) {
/* line = A line WITHOUT `\n` */
// int i, rawnr;
char p0[200], p1[200];
// char tmp[512], part[512];
if (line[0]!='\0') {
// trim(line);
// Split(line,' ',0,p0);
// Split(line,' ',1,p1);
strncpy(p0,line,3);
p0[3]=0;
strncpy(p1,&line[4],2);
p1[2]=0;
/*if (strncasecmp(p1,"G",strlen("G"))!=0)*/
printf("%s<--\n",line);
printf("p0: %s - p1: >%s<\n",p0,p1);
if (!strncasecmp(p1,"EB",strlen("EB"))) { /* End of Burst */
printf("Got EB!!\n");
//Tok_EA(servfd);
//if (joined==FALSE) {
/*sprintf (tmp, "JOIN %s\r\n", HOMECHAN);
SendLine(tmp, TRUE, servfd);
joined=TRUE;*/
//}
}
}
}
int main(void) {
GetLine("Foo Bar",0);
GetLine("Foo EBar",0);
return 0;
}
Yet I would write some things differently and there are some redundancy in the code, there is nothing wrong with any of the code you have shown to me.
Sample input (contents of file named "input"):
Quote:
AB N AliTriX 1 1068972084 wer alitrix.homelinux.net +oiwg B]AAAB ABAAB :Ali
AB N blaat 1 1068972106 wer alitrix.homelinux.net +iw B]AAAB ABAAC :Ali
AB N AliTriX_ 1 1068972109 wer alitrix.homelinux.net +iw B]AAAB ABAAD :Ali
AB B #vodkaz 1068971831 APAAA
AB B #suikode 1068971831 APAAA
AB B #feds 1068971820 ABAAD,ABAAC,ABAAB,APAAA,ABAAA
AB B #coder-com 1068971818 +l 12 ABAAB,APAAA,ABAAA
AB EB
AB EA
APAAA R u :AX
AB G !1068994838.36479 go.moo.oh.yes.they.do 1068994838.36479
AB SQ alitrix.homelinux.net 0 :Ping timeout
toni@mario:~/work/tst/cmp$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.2/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=
gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.2 (Debian)
toni@mario:~/work/tst/cmp$ gcc -Wall casecmp.c
toni@mario:~/work/tst/cmp$ ./a.out < input
AB N AliTriX 1 1068972084 wer alitrix.homelinux.net +oiwg B]AAAB ABAAB :Ali<--
p0: AB - p1: >N<
AB N blaat 1 1068972106 wer alitrix.homelinux.net +iw B]AAAB ABAAC :Ali<--
p0: AB - p1: >N<
AB N AliTriX_ 1 1068972109 wer alitrix.homelinux.net +iw B]AAAB ABAAD :Ali<--
p0: AB - p1: >N<
AB B #vodkaz 1068971831 APAAA<--
p0: AB - p1: >B<
AB B #suikode 1068971831 APAAA<--
p0: AB - p1: >B<
AB B #feds 1068971820 ABAAD,ABAAC,ABAAB,APAAA,ABAAA<--
p0: AB - p1: >B<
AB B #coder-com 1068971818 +l 12 ABAAB,APAAA,ABAAA<--
p0: AB - p1: >B<
AB EB<--
p0: AB - p1: >EB<
Got EB!!
AB EA<--
p0: AB - p1: >EA<
APAAA R u :AX<--
p0: APAAA - p1: >R<
AB G !1068994838.36479 go.moo.oh.yes.they.do 1068994838.36479<--
p0: AB - p1: >G<
AB SQ alitrix.homelinux.net 0 :Ping timeout<--
p0: AB - p1: >SQ<
toni@mario:~/work/tst/cmp$
As said, the code is ok. Works for me. Either you mess up something in other parts of the program or your programming environment is plain broken.
If the testcase above does't give same results in your computer, you have either broken gcc or broken glibc (or both).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.