What is the newline character in Free Basic?

New to FreeBASIC? Post your questions here.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: What is the newline character in Free Basic?

Post by dodicat »

printf can be used.
Remember to put the escape character in front of the string to handle things like \n
http://www.cplusplus.com/reference/cstdio/printf/
I have made one small difference to suit freebasic in the first printf.
(NOTE: I use #macro as a convenient way to hold comments, it has nothing to do with running code)

Code: Select all


#include "crt.bi"

   printf (!"Characters: %c %c \n", asc("a"), 65)
   printf (!"Decimals: %d %ld\n", 1977, 650000L)
   printf (!"Preceding with blanks: %10d \n", 1977)
   printf (!"Preceding with zeros: %010d \n", 1977)
   printf (!"Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100)
   printf (!"floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416)
   printf (!"Width trick: %*d \n", 5, 10)
   printf (!"%s \n", "A string")
 '===========================  
   
 #macro C_code_from_the_link
 /* printf example */
#include <stdio.h>

int main()
{
   printf ("Characters: %c %c \n", 'a', 65);
   printf ("Decimals: %d %ld\n", 1977, 650000L);
   printf ("Preceding with blanks: %10d \n", 1977);
   printf ("Preceding with zeros: %010d \n", 1977);
   printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
   printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
   printf ("Width trick: %*d \n", 5, 10);
   printf ("%s \n", "A string");
   return 0;
}
#endmacro
   
   
#macro C_output_from_the_link
Characters: a A
Decimals: 1977 650000
Preceding with blanks:       1977
Preceding with zeros: 0000001977
Some different radices: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick:    10
A string
#endmacro

sleep
 
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: What is the newline character in Free Basic?

Post by MrSwiss »

@dodicat,
dodicat wrote:NOTE: I use #macro as a convenient way to hold comments, it has nothing to do with running code
I don't see a reason for that, you could simply stick them into a multiline comment: /' ... '/ ???
Seems to me to be a 'clean' solution (as provided by the language itself).
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: What is the newline character in Free Basic?

Post by dodicat »

I always get mixed up and have to redo them.
nov79
Posts: 47
Joined: Feb 23, 2020 15:31

Re: What is the newline character in Free Basic?

Post by nov79 »

Thanks all of you.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: What is the newline character in Free Basic?

Post by D.J.Peters »

Print numbers as string that is all

Code: Select all

print str(sqr(2))
If you print numbers the space is a place holder for an minus sign

Code: Select all

print -1
print atn(1)*4
Imagine you print a table in the console
without the placeholder the result of negative and positive numbers would look ugly right ?

Joshy

try it if you like

Code: Select all

for x as integer = 1 to 4
  for y as integer = 1 to 4
    print int((rnd-rnd)*9),
  next
  print
next
print
for x as integer = 1 to 4
  for y as integer = 1 to 4
    print str(int((rnd-rnd)*9)),
  next
  print
next
print
sleep
Post Reply