Created
June 13, 2022 11:21
-
-
Save aynik/7cf62867083bc4b97cef9248579530ac to your computer and use it in GitHub Desktop.
odd-bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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