Chaga Programming Language: Chapter 7: Input and Output

Input from the keyboard

getchar

function getchar (void) return (unsigned char, int)

  • The getchar function reads one character from standard input (i.e. keyboard). It returns an unsigned character to identifier1 upon success. If an error occurred, getchar returns an integer value -1 to identifier2.
  • set (identifier1, identifier2) = getchar (void);

Output to the screen

print

  • The print procedure can display a mixture of text and values from variables to standard output.
  • procedure print (expression)
  • Example: call print ("Hello, ", firstname);
  • Example: call print (sum, "represents the tenth term of the Fibonacci series");
  • Example: call print ("This", "message", "is", "separated", "into", "many", "parts");

putchar

  • The putchar procedure sends one unsigned character from expression to standard output.
  • procedure putchar (expression)
  • Example: call putchar (byte);
  • Example: call putchar ('\t');
  • Example: call putchar ("\n");

memory_allocate

  • The memory_allocate function requests a chunk of heap memory from the operating system. The amount of memory is calculated based upon the datatype times the number of number of records of that datatype. If the datatype is an enum datatype, the size of the datatype will be determined by the datatype in the enumerated list that requires the most amount of storage.
  • Upon success, the memory_allocate function returns a pointer to the memory allocated by the operating system from the heap. Upon failure, the memory_allocate function returns NULL.
  • function memory_allocate (datatype, number of records of datatype) return (pointer)
  • Example: set my_pointer.self.address = memory_allocate (char, 1024);

Copyright © 2025, 2026 Robert James Bruce.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at https://www.gnu.org/licenses/fdl-1.3.html