Skip to content

Instantly share code, notes, and snippets.

@nakal
Created December 30, 2015 09:47
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 nakal/05443bf8d09a13b23d9e to your computer and use it in GitHub Desktop.
Save nakal/05443bf8d09a13b23d9e to your computer and use it in GitHub Desktop.
C program that checks if the given STDIN stream is standard ASCII
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int found_non_ascii = 0;
while (!ferror(stdin) && !feof(stdin)) {
size_t s;
char buf[1024];
s = fread(buf, sizeof(buf), 1, stdin);
for (; !found_non_ascii && s > 0; s--) {
if (buf[s - 1] < 0)
found_non_ascii = 1;
}
}
return ferror(stdin) || found_non_ascii;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment