ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 33a484f was
466fa01,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
add diagrams and example programs
|
-
Property mode set to
100644
|
File size:
968 bytes
|
Rev | Line | |
---|
[466fa01] | 1 | #include <stdio.h> |
---|
| 2 | |
---|
| 3 | typedef struct { |
---|
| 4 | void * next; |
---|
| 5 | char ch; |
---|
| 6 | int g, b; |
---|
| 7 | } Fmt; |
---|
| 8 | |
---|
| 9 | void format( Fmt * f ) { |
---|
| 10 | if ( __builtin_expect(f->next != 0, 1) ) goto *f->next; |
---|
| 11 | f->next = &&s1; |
---|
| 12 | for ( ;; ) { |
---|
| 13 | for ( f->g = 0; f->g < 5; f->g += 1 ) { // groups |
---|
| 14 | for ( f->b = 0; f->b < 4; f->b += 1 ) { // blocks |
---|
| 15 | return; |
---|
| 16 | s1: ; |
---|
| 17 | if ( f->ch == '\0' ) goto fini; // EOF ? |
---|
| 18 | while ( f->ch == '\n' ) return; // ignore |
---|
| 19 | printf( "%c", f->ch ); // print character |
---|
| 20 | } |
---|
| 21 | printf( " " ); // block separator |
---|
| 22 | } |
---|
| 23 | printf( "\n" ); // group separator |
---|
| 24 | } |
---|
| 25 | fini: |
---|
| 26 | if ( f->g != 0 || f->b != 0 ) printf( "\n" ); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | int main() { |
---|
| 30 | Fmt fmt = { NULL }; |
---|
| 31 | format( &fmt ); // prime |
---|
| 32 | for ( ;; ) { |
---|
| 33 | scanf( "%c", &fmt.ch ); // direct read into communication variable |
---|
| 34 | if ( feof( stdin ) ) break; |
---|
| 35 | format( &fmt ); |
---|
| 36 | } |
---|
| 37 | fmt.ch = '\0'; |
---|
| 38 | format( &fmt ); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | // Local Variables: // |
---|
| 42 | // tab-width: 4 // |
---|
| 43 | // compile-command: "gcc-8 Format1.c" // |
---|
| 44 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.