Skip to content

Instantly share code, notes, and snippets.

@aynik
Created June 13, 2022 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aynik/5e494a423aff65ee678ac52f20639e61 to your computer and use it in GitHub Desktop.
Save aynik/5e494a423aff65ee678ac52f20639e61 to your computer and use it in GitHub Desktop.
even-bytes
#!/usr/bin/env C -m
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void even_bytes(const int bytes)
{
int c;
do
{
for (int i = 0; i < bytes; i++)
{
c = fgetc(stdin);
if (feof(stdin))
{
goto done;
}
fputc(c, stdout);
}
for (int i = 0; i < bytes; i++)
{
c = fgetc(stdin);
if (feof(stdin))
{
goto done;
}
}
}
while (c != EOF);
done:
fclose(stdout);
}
void usage()
{
printf("Usage: even-bytes\n");
printf(" even-bytes <bytes per> < in > out\n");
}
int main(int argc, char **argv)
{
int bytes = 1;
if (argc > 1) {
bytes = atoi(argv[1]);
}
if (argc < 1)
{
usage();
return 0;
}
even_bytes(bytes);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment