Created
September 25, 2012 21:30
-
-
Save JAChapmanII/3784579 to your computer and use it in GitHub Desktop.
read a file character by character
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 <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