2021 templates

This commit is contained in:
2021-12-02 16:37:50 +01:00
parent 2d431892da
commit 7a1a200a73
11 changed files with 1645 additions and 0 deletions

58
2021/templates/ex1-c.c Normal file
View File

@@ -0,0 +1,58 @@
/* ex1-c: Advent2021 game, day 1/game 1
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "debug.h"
#define XMOVE 3
int my_strlen(str)
char *str;
{
int i;
for (i=0; *str; ++i, ++str)
;
return i;
}
static int usage(char *prg)
{
fprintf(stderr, "Usage: %s [-ilw] [file...]\n", prg);
return 1;
}
int main(int ac, char **av)
{
int opt;
char str[80];
while ((opt = getopt(ac, av, "d:f:")) != -1) {
switch (opt) {
case 'd':
debug_level_set(atoi(optarg));
break;
default:
return usage(*av);
}
}
printf("optind = %d ac = %d\n", optind, ac);
if (optind < ac)
return usage(*av);
scanf("%s", str); /* ignore 1st line */
while (scanf("%s", str) != EOF) {
line++;
col+=XMOVE;
linelen=my_strlen(str);
mod=col%linelen;
if (*(str+mod) == '#')
count++;
}
printf ("%s : lines:%d pos:%d found:%d\n", *av, line, col, count);
exit (0);
}