Last active
October 2, 2017 03:13
-
-
Save io12/a3c2ae2ea50e224f735127d3057a7702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, const char *argv[]) | |
{ | |
FILE *fp; | |
int c; | |
unsigned int lineno = 1, colno = 1; | |
if (argc != 2) { | |
fprintf(stderr, "Usage: %s file\n", argv[0]); | |
exit(EXIT_FAILURE); | |
} | |
fp = fopen(argv[1], "r"); | |
if (fp == NULL) { | |
fprintf(stderr, "%s: error: %s\n", argv[0], strerror(errno)); | |
exit(EXIT_FAILURE); | |
} | |
for (;;) { | |
c = fgetc(fp); | |
if (c == EOF) { | |
fprintf(stderr, "None found. Entire file is ASCII.\n"); | |
exit(EXIT_FAILURE); | |
} | |
if ((unsigned char) c >> 7 == 1) { | |
fprintf(stderr, "Found UTF-8 character at %s:%u:%u\n", | |
argv[1], lineno, colno); | |
exit(EXIT_SUCCESS); | |
} | |
if (c == '\n') { | |
colno = 1; | |
lineno++; | |
} | |
colno++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment