Skip to content

Instantly share code, notes, and snippets.

@JAChapmanII
Created September 25, 2012 21:30
Show Gist options
  • Save JAChapmanII/3784579 to your computer and use it in GitHub Desktop.
Save JAChapmanII/3784579 to your computer and use it in GitHub Desktop.
read a file character by character
#include <stdio.h>
#include <stdbool.h>
int main(int argc, char **argv) {
char *fileName = argv[1];
FILE *file = fopen(fileName, "r");
char c;
while(true) {
int ret = fscanf(file, "%c", &c);
if(ret == EOF || feof(file))
break;
printf("c: %d (%c)\n", c, c);
}
fclose(file);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment