English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What happens when you try to convert a string to an integer value and the string does not contain valid integer characters?

2007-01-08 07:38:21 · 3 answers · asked by Vector 1 in Computers & Internet Programming & Design

3 answers

Then the conversion fails?

You might get a more meaningful response if you gave us a context, like: I'm using C and converting a character buffer using C string functions.

I'll use the above as an example:
char buffer = "asd"
if(!strtol(buffer, NULL, 0))
{
//Code to execute because conversion failed
}

2007-01-08 07:45:25 · answer #1 · answered by csanon 6 · 1 0

A good programmer/analyst does data validity checking before executing a command where there is a risk of a program bombing with a nasty error message such as invalid integer character. A good programmer/analyst also has an error routine which checks the error messages and gives meaningful instruction about what kind of data is valid for a particular data field

2007-01-08 16:48:00 · answer #2 · answered by Denise T 5 · 0 0

Depends on the programming language. What language are you using? The possible outcomes are:

(1) Program crashes
(2) Returns [null]
(3) Returns 0

The best thing to do is to setup an error handler...so if you were using Visual Basic for example, you would say:

if isNumeric(myString) then
myNum = cInt(myString)
else
myNum = -9999
end if

2007-01-08 16:03:00 · answer #3 · answered by Cars & Computers 1 · 0 0

fedest.com, questions and answers