I am trying to learn Dart language by transferring the exercises my school taught to C programming.
The first exercise in our C pool is to write the print_alphabet() function, which prints the lower case alphabet; It is forbidden to print the alphabet directly.
In POSIX C, a simple solution would be:
#include <unistd.h> void print_alphabet(void) { char c; c = 'a'; while (c <= 'z') { write(STDOUT_FILENO, &c, 1); c++; } } int main(void) { print_alphabet(); return (0); }
However, as far as I know, in the current version of Dart (1.1.1) there is no easy way to deal with characters. The farthest I came up with (for my first version):
void print_alphabet() { var c = "a".codeUnits.first; var i = 0; while (++i <= 26) { print(c.toString()); c++; } } void main() { print_alphabet(); }
Which prints the ASCII value of each character, one per line, as a string ("97" ... "122"). Not quite what I intended ...
I am trying to find a suitable way to do this. But the lack of a char type, similar to what is in C, gives me a bit of time as a beginner!
source share