Asking for advice on formmated string

Raz A.
Haifa,

Sep 11, 2017
82 Posts

0  |  0  

Re: Asking for advice on formmated string

Lets say i have a char[100] which is forrmatted like this: “%d,%d,%d,%.2f,%.2f”.

What is the best way in ATEASY to get all 5 varible values? ( long,long,long,float, float).

I wanted to work with Split(sStr,",") but it only works with String type.

DrATEasy (Ron Y.)
Mission Viejo, CA

Sep 11, 2017
358 Posts

0  |  0  

Re: Asking for advice on formmated string

See Language.prg example, Test 7.9  sscanf, , the test shows example for using sscanf with up to 16 variables. Copy to your module the MSVCRT library to use it.

Raz A.
Haifa,

Sep 17, 2017
82 Posts

0  |  0  

Re: Asking for advice on formmated string

The first parameter of sscanf is of String type but i have char type (char[100])

so i receive an error :
"Compiler error #612: Type of argument is incompatible with Val parameter 'acBuffer' in procedure 'EDTU_TEST.msvcrt.sscanf', found in 'EDTU_TEST.RFTransmissionDL_LOOP' in line 54"


What can i do?

Paul T.
Maennedorf, Zurich

Sep 17, 2017
63 Posts

0  |  0  

Re: Asking for advice on formmated string

Hi Raz,

I've tried something related to your requirement. See code snippet below.
Actually, if you have an array of chars, you need to specify in some way which chars are integer numbers and which are part of your floating point numbers...

That's why I used "," and "." in the creation of the string below.
I obtained "1", "2" and "3" as integers (long) and "4.53" & "6.82" as floting point numbers (double).

! set the buffer size
SetLen(s, 256)
acChar = {'1','2','3','4','5','3','6','8','2'}

s = chr(acChar[0]) + "," + chr(acChar[1]) + "," + chr(acChar[2]) + "," + chr(acChar[3]) + "." + chr(acChar[4])+ chr(acChar[5])+ ","+ chr(acChar[6]) + "." + chr(acChar[7])+ chr(acChar[8])

i=sscanf(s, "%d, %d, %d, %lf, %lf", lLong1, lLong2, lLong3, dDouble1, dDouble2)



I hope it helps you. I don't know a better method to do this task...

Best regards,
Paul T.

DrATEasy (Ron Y.)
Mission Viejo, CA

Sep 18, 2017
358 Posts

0  |  0  

Re: Asking for advice on formmated string

Can you paste you code and how you defined your variables?

The first argument is the format spec (string) and the second is the second is the buffer to parse and convert the the arguments. Both of them can be string of array of char. See also http://www.cplusplus.com/reference/cstdio/sscanf/

Raz A.
Haifa,

Sep 23, 2017
82 Posts

0  |  0  

Re: Asking for advice on formmated string

There is a Char type and String type. i must work with a Char[100] and not string. sscanf receives a String type, not char or char[100]

when i send char[100] type it says:

"Compiler error #612: Type of argument is incompatible with Val parameter 'acBuffer' in procedure 'EDTU_TEST.msvcrt.sscanf', found in 'EDTU_TEST.RFTransmissionDL_LOOP' in line 54"


cant i just do this?

sStringType = acCharType

Solution Available
Paul T.
Maennedorf, Zurich

Sep 24, 2017
63 Posts

1  |  0  

Re: Asking for advice on formmated string

Hi Raz,

Yes, I think you can assign the char array to the string, but how can you tell which chars are parts of integer numbers and which are parts of floating point numbers?
You stated before that you want to extract both integer and floating point numbers, right?

Regards,
Paul

Raz A.
Haifa,

Sep 24, 2017
82 Posts

0  |  0  

Re: Asking for advice on formmated string

Ill assign the char array to the string and then ill use sscanf.....

Thats what i did. and it works



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]