Created
March 27, 2015 01:20
-
-
Save nickrobson/f668ad947f902e732354 to your computer and use it in GitHub Desktop.
Get the contents of a file.
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(int argc, char* argv[]) { | |
char fileName[30]; | |
printf("Enter file name: "); | |
scanf("%s", fileName); | |
FILE* file = fopen(fileName, "r"); | |
if (file == NULL) { | |
perror("Error while opening the file.\n"); | |
return EXIT_FAILURE; | |
} | |
printf("Input characters: "); | |
char character; | |
while ((character = getc(file)) != EOF) { | |
// do something with the character! e.g. print it | |
printf("%c", character); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment