Created
December 30, 2015 09:47
-
-
Save nakal/05443bf8d09a13b23d9e to your computer and use it in GitHub Desktop.
C program that checks if the given STDIN stream is standard ASCII
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
#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