P
Pietro Cerutti
Hello,
here I have a strange problem with a real simple strtok example.
The program is as follows:
### BEGIN STRTOK ###
#include <string.h>
#include <stdio.h>
int main()
{
char *input1 = "Hello, World!";
char *tok;
tok = strtok(input1, " ");
if(tok) printf("%s\n", tok);
tok = strtok(NULL, " ");
if(tok) printf("%s\n", tok);
return(0);
}
### END STRTOK ###
Now, when I run it from the command line, I get a bus error:
### BEGIN COMMAND LINE OUTPUT ###
Exit 138
### END COMMAND LINE OUTPUT ###
When I run it step by step in GDB, the program terminates normally:
### BEGIN DEBUGGER OUTPUT ###
[snip]GDB copyright and bla bla[/snip]
(gdb) break main
Breakpoint 1 at 0x8048570: file strtok.c, line 6.
(gdb) run
Starting program: /home/piter/strtok
Breakpoint 1, main () at strtok.c:6
6 char *input1 = "Hello, World!";
(gdb) next
10 tok = strtok(input1, " ");
(gdb)
11 if(tok) printf("%s\n", tok);
(gdb)
Hello,
13 tok = strtok(NULL, " ");
(gdb)
14 if(tok) printf("%s\n", tok);
(gdb)
World!
16 return(0);
(gdb)
18 }
(gdb)
0x08048485 in _start ()
(gdb)
Single stepping until exit from function _start,
which has no line number information.
Program exited normally.
(gdb)
### END DEBUGGER OUTPUT ###
Is there something I'm missing wrt C and/or strtok, or it's rather a
problem related to my environment (in which case I'll be happy to post
in the right newsgroup) ?
Thanx in advance
here I have a strange problem with a real simple strtok example.
The program is as follows:
### BEGIN STRTOK ###
#include <string.h>
#include <stdio.h>
int main()
{
char *input1 = "Hello, World!";
char *tok;
tok = strtok(input1, " ");
if(tok) printf("%s\n", tok);
tok = strtok(NULL, " ");
if(tok) printf("%s\n", tok);
return(0);
}
### END STRTOK ###
Now, when I run it from the command line, I get a bus error:
### BEGIN COMMAND LINE OUTPUT ###
Bus error (core dumped)gcc -ggdb -Wall -o strtok strtok.c
./strtok
Exit 138
### END COMMAND LINE OUTPUT ###
When I run it step by step in GDB, the program terminates normally:
### BEGIN DEBUGGER OUTPUT ###
GNU gdb 6.1.1 [FreeBSD]gdb ./strtok
[snip]GDB copyright and bla bla[/snip]
(gdb) break main
Breakpoint 1 at 0x8048570: file strtok.c, line 6.
(gdb) run
Starting program: /home/piter/strtok
Breakpoint 1, main () at strtok.c:6
6 char *input1 = "Hello, World!";
(gdb) next
10 tok = strtok(input1, " ");
(gdb)
11 if(tok) printf("%s\n", tok);
(gdb)
Hello,
13 tok = strtok(NULL, " ");
(gdb)
14 if(tok) printf("%s\n", tok);
(gdb)
World!
16 return(0);
(gdb)
18 }
(gdb)
0x08048485 in _start ()
(gdb)
Single stepping until exit from function _start,
which has no line number information.
Program exited normally.
(gdb)
### END DEBUGGER OUTPUT ###
Is there something I'm missing wrt C and/or strtok, or it's rather a
problem related to my environment (in which case I'll be happy to post
in the right newsgroup) ?
Thanx in advance