G
Guest
I tried to submit this as a bug, but the web page failed to work. I am using visual C++ 6 SP5. I am running on a Window ME machine with 128 megs, gigs of disk, PentiumII 400. I was developing code to parse text delimited by commas. It worked fine as long as none of the fields were empty, i.e. text,text,text worked, but text,,text did not. First I tried it with sscanf then with strtok. When I built the code below in a debug build it crashed when run with an exception in strtok
startcode------------------------
#include "stdafx.h
#include <stdio.h
#include <string.h
#include <stdlib.h
#include <conio.h
int main(int argc, char* argv[]
char a[200], b[20], c[20], *p
sscanf("test,,test2", "%19[^,],%19[^,],%s", a, b, c )
printf( "a=\'%s\' should be \'test\', b=\'%s\' should be \'\', c=\'%s\' should be \'test2\'\n", a, b, c )
p=strtok("test,,test2",",")
printf( "tok=\'%s\' should be \'test\'\n", p )
p=strtok(NULL,"," )
printf( "tok=\'%s\' should be \'\'\n", p )
p=strtok(NULL,",")
if ( p==NULL
printf( "tok was NULL, should be \'test2\'\n" )
els
printf( "tok=\'%s\', should be \'test2\'\n", p )
getche()
return 0
endcode---------------------------
startcode------------------------
#include "stdafx.h
#include <stdio.h
#include <string.h
#include <stdlib.h
#include <conio.h
int main(int argc, char* argv[]
char a[200], b[20], c[20], *p
sscanf("test,,test2", "%19[^,],%19[^,],%s", a, b, c )
printf( "a=\'%s\' should be \'test\', b=\'%s\' should be \'\', c=\'%s\' should be \'test2\'\n", a, b, c )
p=strtok("test,,test2",",")
printf( "tok=\'%s\' should be \'test\'\n", p )
p=strtok(NULL,"," )
printf( "tok=\'%s\' should be \'\'\n", p )
p=strtok(NULL,",")
if ( p==NULL
printf( "tok was NULL, should be \'test2\'\n" )
els
printf( "tok=\'%s\', should be \'test2\'\n", p )
getche()
return 0
endcode---------------------------