Integers print with leading space?

New to FreeBASIC? Post your questions here.
Post Reply
dkr
Posts: 40
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Integers print with leading space?

Post by dkr »

Where o_ncards is dimensioned as an integer, the following code prints the line with a space between the comma (c) and the integer??
I know I can use print using, but why the leading space?

Code: Select all

c = ","
print #out_f, "NUM_CARDS";c;o_ncards
Output:
NUM_CARDS, 5

Thanks,
Darren
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Integers print with leading space?

Post by deltarho[1859] »

We get a leading space with signed integers, but not unsigned integers.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Integers print with leading space?

Post by paul doe »

dkr wrote:...
I know I can use print using, but why the leading space?
...
Indeed, the leading space is for the sign. If you want to get rid of it (in case of positive integers), simply convert the number before printing (either with the & string contatenation operator or with the str() function:

Code: Select all

dim as integer _
  o_ncards => 5
dim as string _
  c => ","

? "NUM_CARDS"; c; o_ncards

? "NUM_CARDS"; c & o_ncards
? "NUM_CARDS"; c; str( o_ncards )

sleep()
dkr
Posts: 40
Joined: Nov 20, 2015 15:17
Location: Alabama, USA

Re: Integers print with leading space?

Post by dkr »

Ok, great. I forgot about the sign

Thanks,
Darren
Post Reply