bricolages...

This commit is contained in:
tTh
2023-02-11 12:19:00 +01:00
parent 43202ab62e
commit a47c1f6d7a
10 changed files with 89 additions and 22 deletions

10
code/C/Makefile Normal file
View File

@@ -0,0 +1,10 @@
# exemples pour le chapitre sur le C
# new Sat Feb 11 12:06:34 CET 2023
no-op: no-op.c Makefile
gcc -Wall $< -o $@
slowprint: slowprint.c Makefile
gcc -Wall $< -o $@

18
code/C/no-op.c Normal file
View File

@@ -0,0 +1,18 @@
/*
* no-op.c is an useless shell filter
*/
#include <stdio.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
int quux, baz;
while (EOF != (quux=getchar())) {
baz = toupper(quux);
if ('O'==baz || 'P'==baz) continue;
putchar(quux);
}
return 0;
}

20
code/C/slowprint.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int c;
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 115 * 1000 * 1000;
while ( EOF != (c=getchar()) )
{
putchar(c);
fflush(stdout);
nanosleep(&ts, NULL);
}
return 0;
}