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/7cf62867083bc4b97cef9248579530ac to your computer and use it in GitHub Desktop.
Save aynik/7cf62867083bc4b97cef9248579530ac to your computer and use it in GitHub Desktop.
odd-bytes
#!/usr/bin/env C -m
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void odd_bytes(const int bytes)
{
int c;
do
{
for (int i = 0; i < bytes; i++)
{
c = fgetc(stdin);
if (feof(stdin))
{
goto done;
}
}
for (int i = 0; i < bytes; i++)
{
c = fgetc(stdin);
if (feof(stdin))
{
goto done;
}
fputc(c, stdout);
}
}
while (c != EOF);
done:
fclose(stdout);
}
void usage()
{
printf("Usage: odd-bytes\n");
printf(" odd-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;
}
odd_bytes(bytes);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment