ATOI error
champ
Posts: 261
I don't understand why doesn't this work...
cOutput[cCount_] = ATOI(cString[cCount_])
when this does...
cOutput[cCount_] = cString[cCount_] - '0'
Here's the code...
cOutput[cCount_] = ATOI(cString[cCount_])
...this output is produced:
Line 1 :: ParseVideo cString: 123445 - 11:39:18
Line 2 :: CIpLibrary::Atoi - Error - 11:39:18
Line 3 :: Library Call error on Line 746 - 11:39:18
Line 4 :: ParseVideo cString[1]: 1 cOutput[1]: 0 - 11:39:18
Line 5 :: CIpLibrary::Atoi - Error - 11:39:18
...and so on
Using the line...
cOutput[cCount_] = cString[cCount_] - '0'
...this output is produced:
Line 1 :: ParseVideo cString: 123445 - 11:55:18
Line 2 :: ParseVideo cString[1]: 1 cOutput[1]: 1 - 11:55:18
[/code]
champ
cOutput[cCount_] = ATOI(cString[cCount_])
when this does...
cOutput[cCount_] = cString[cCount_] - '0'
Here's the code...
DEFINE_FUNCTION ParseVideo (CHAR cString[]) STACK_VAR CHAR cCount_ CHAR cOutput[7] { SEND_STRING 0, "'ParseVideo cString: ', cString" FOR (cCount_ = 1; cCount_ < 7; cCount_++) { cOutput[cCount_] = ATOI(cString[cCount_]) // this produces CIpLibrary::Atoi - Error //cOutput[cCount_] = cString[cCount_] - '0' // this works SEND_STRING 0, "'ParseVideo cString[', ITOA(cCount_), ']: ', cString[cCount_], ' cOutput[', ITOA(cCount_) ,']: ', ITOA(cOutput[cCount_])" } cString = RIGHT_STRING(cString,LENGTH_STRING(cString)-6) SEND_STRING 0, "'ParseVideo cString: ', cString" }Using the line...
cOutput[cCount_] = ATOI(cString[cCount_])
...this output is produced:
Line 1 :: ParseVideo cString: 123445 - 11:39:18
Line 2 :: CIpLibrary::Atoi - Error - 11:39:18
Line 3 :: Library Call error on Line 746 - 11:39:18
Line 4 :: ParseVideo cString[1]: 1 cOutput[1]: 0 - 11:39:18
Line 5 :: CIpLibrary::Atoi - Error - 11:39:18
...and so on
Using the line...
cOutput[cCount_] = cString[cCount_] - '0'
...this output is produced:
Line 1 :: ParseVideo cString: 123445 - 11:55:18
Line 2 :: ParseVideo cString[1]: 1 cOutput[1]: 1 - 11:55:18
[/code]
champ
0
Comments
"cCount_" and "cOutput" are CHAR string, so you can't use ATOI() if you are sending to a CHAR string. if cOutput was an INTEGER then it would work.
I don't know what your trying to do but this may help!
It was sloppy programming not using an INTEGER or TYPE_CAST for cOutput but according to the Netlinx manual type conversion rules the program should just truncate the two higher bytes leaving me with a CHAR value that still works and a compiler warning which didn't happen.
In my program cOutput[] is a global which holds the value of what input is routed to each output of a video matrix. I just changed it to a local for testing.
I want to convert the value from ASCII to a char (or integer) because I use the code with other switchers with up to 255 inputs.
What you have should work just fine with one minor adjustment.
Change:
cOutput[cCount_] = ATOI(cString[cCount_])
To:
cOutput[cCount_] = ATOI(?cString[cCount_]?)
See this thread for an explanation:
http://www.amxforums.com/showthread.php?t=1050
The working line is...
cOutput[cCount_] = TYPE_CAST(ATOI("cString[cCount_]")
Thanks
Champ