I've just moved from Pascal to C++ . I face really weird problem with the debugger in Visual Studio C++ 6.0 . belose is my source : [cpp]
#include<iostream>
#include<string>
using namespace std ;
char * nextToken(char *b){
char static *tem ;
if (b==NULL) {
if (tem == NULL) return NULL ;
char * si = new char[(strchr(tem,' ')-tem)];
strncpy(si ,tem,(strchr(tem,' ')-tem));
si+='\0' ;
return si ;
tem += strlen(si) ;
while (tem[0] == ' ') tem++ ;
}
else {
tem = new char[strlen(b)] ;
tem = strcpy(tem,b);
cout<<tem ;
return NULL ;
}
}
void main(){
char s[100] , c;
do {
cout<<"Enter a string or q to exit\n" ;
cin.getline(s , 100) ;
if (strcmp(s,"q")==0) break ;
nextToken(s);
do {
cout<<"press n for next token , press s for stopping" <<endl;
cin >> c ;
char * s = nextToken(NULL) ;
if (c=='n' && s != NULL ) cout<< s ;
else break ;
} while (1) ;
} while (1) ;
}
[/cpp]
I should state firstly there's no silly compilation error here . Everything compiled OK but still got stuck while running .
It's just a simple one simulating the strtok func. in C++. But when I try to view the static "char * tem" variable in function " char * nextToken(char*) , the debugger dunt understand .(Error : symbol "tem" not found".
I tried to changed it into #include<string> instead of #include<string.h> , then try to view it by ::tem , but it doesnt help also .
Thnx for any reply
