this piece of code worked fine on my machine, but it doesn’t on my school server.
The program is a simple text editor and that little part just prints out error when there was no line number input.
This is just a segment of my code. On my machine, when no line number is inputted, it goes to the if statement. On the server however, it doesn’t Instead all blank spaces become ‘0’.
char c[6];
int line = 0;
cin.getline( c, 6 );
.
.
.
else if( c[0] == 'I' ){
line = atoi( &c[2] );
if( c[2] == '\0' ){
cout << "Missing line number for insert" << endl;
}
}
Any idea? Or anybody know a better way of dealing with this problem?
One possibility is that you build in debug mode at home, in which case your ‘c’ buffer gets initialized with zeros. And at school, you build with ‘release’ mode, in which case your c buffer is not initialized, but will have indeterminate values.
You should initialized your ‘c’ buffer with zeros with a line like