Skip to content

Instantly share code, notes, and snippets.

@nakal
Created Dec 30, 2015
Embed
What would you like to do?
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