Created
June 13, 2022 11:21
-
-
Save aynik/5e494a423aff65ee678ac52f20639e61 to your computer and use it in GitHub Desktop.
even-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 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