Z
Zach
I open a file and read each line, want to use strtok() to tokenize it:
(code snippets)
char tokenlist[2] = {':',' '};
char *p1, *p2;
unsigned int i;
for(i=0; i <= sizeof(tokenlist[2]); i++){
p1 = strtok(line,tokenlist);
printf("token 1: %s\n",p1);
p2 = strtok(NULL,tokenlist[i+1]);
printf("token 2: %s\n",p2);
}
when i compile i get the warning:
newmain4.c: In function ‘main’:
newmain4.c:65: warning: passing argument 2 of ‘strtok’ makes pointer
from integer without a cast
newmain4.c:68: warning: passing argument 2 of ‘strtok’ makes pointer
from integer without a cast
lines 65 and 68 are my strtok calls.
strtok returns a pointer value of type (char *), p1 and p2 are
pointers of type (char *) so what is the problem?
I ran it in gdb but it did not give a very detailed message. Just
mentioned strtok:
chaos@nickel:~/myprojects/netrek-log-parser$ gdb --args ./newmain4
test.log
GNU gdb 6.4.90-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db
library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) run
Starting program: /afs/club.cc.cmu.edu/usr/chaos/myprojects/netrek-log-
parser/newmain4 test.logToken 0: :
Token 1:
Entering fgets while loop...
hello hello hello
Program received signal SIGSEGV, Segmentation fault.
0xb7ef8c44 in strtok () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt full
#0 0xb7ef8c44 in strtok () from /lib/tls/i686/cmov/libc.so.6
No symbol table info available.
#1 0x00000000 in ?? ()
No symbol table info available.
(gdb) quit
The program is running. Exit anyway? (y or n) y
Is there a way to get gdb to give more detailed output?
Zach
(code snippets)
char tokenlist[2] = {':',' '};
char *p1, *p2;
unsigned int i;
for(i=0; i <= sizeof(tokenlist[2]); i++){
p1 = strtok(line,tokenlist);
printf("token 1: %s\n",p1);
p2 = strtok(NULL,tokenlist[i+1]);
printf("token 2: %s\n",p2);
}
when i compile i get the warning:
newmain4.c: In function ‘main’:
newmain4.c:65: warning: passing argument 2 of ‘strtok’ makes pointer
from integer without a cast
newmain4.c:68: warning: passing argument 2 of ‘strtok’ makes pointer
from integer without a cast
lines 65 and 68 are my strtok calls.
strtok returns a pointer value of type (char *), p1 and p2 are
pointers of type (char *) so what is the problem?
I ran it in gdb but it did not give a very detailed message. Just
mentioned strtok:
chaos@nickel:~/myprojects/netrek-log-parser$ gdb --args ./newmain4
test.log
GNU gdb 6.4.90-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db
library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) run
Starting program: /afs/club.cc.cmu.edu/usr/chaos/myprojects/netrek-log-
parser/newmain4 test.logToken 0: :
Token 1:
Entering fgets while loop...
hello hello hello
Program received signal SIGSEGV, Segmentation fault.
0xb7ef8c44 in strtok () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt full
#0 0xb7ef8c44 in strtok () from /lib/tls/i686/cmov/libc.so.6
No symbol table info available.
#1 0x00000000 in ?? ()
No symbol table info available.
(gdb) quit
The program is running. Exit anyway? (y or n) y
Is there a way to get gdb to give more detailed output?
Zach