所以这就是问题所在。我有一组数据应该是:
int int int int ....
但是,我希望如果我有 1asdas 2 ,我希望能够捕捉到“asdas”部分。但是,此时,如果我只有 1 2,则 endptr 不为 NULL,因此我无法检查该值是只有数字还是数字和字母。这是我的代码:
else if(token != NULL && token2 != NULL && token3 == NULL){
//we POSSIBLY encountered row and column values for the matrix
//convert the two numbers to longs base 10 number
int row = strtol(token, &result, 10);
int col = strtol(token2, &result2, 10);
printf("Result is %s and result2 is %s\n", result, result2);
//check to see if both numbers are valid
//this will be true if there were only 2 digits on the line
if(!result && !result2){
//SUCCESSFULL parsing of row and column
printf("SUCCESSFUL PARSING\n");
}
}
谢谢!