Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- errno = 0;
- const char *filename = "/Users/davidfrenzel/Google Drive/Studium/Semester 1/Programmierung 1/Projects/Uebung4/...";
- FILE *file;
- file = fopen(filename, "r");
- if (file == NULL) {
- fprintf(stderr, "%s\n", strerror(errno));
- exit(1);
- } else{
- printf("The file %s was Found\n", filename);
- }
- return 0;
- }
- No such file or directory
- (You're right!)
- BUT:
- int main() {
- errno = 0;
- const char *filename = "...";
- FILE *file;
- file = fopen(filename, "r");
- if (file == NULL) {
- fprintf(stderr, "%s\n", strerror(errno));
- exit(1);
- } else{
- printf("The file %s was Found\n", filename);
- }
- return 0;
- }
- The file ... was Found
- change the code to:
- int main() {
- errno = 0;
- const char *filename = "...";
- FILE *file;
- file = fopen(filename, "r");
- if (file == NULL || filename == "...") {
- fprintf(stderr, "%s\n", strerror(errno));
- exit(1);
- } else{
- printf("The file %s was Found\n", filename);
- }
- return 0;
- }
- Of course errno won't be set to anything but that way I could tell the programm to return an error (in the function seen in question) if the filename == "...". Kind of as a workaround I guess
Advertisement
Add Comment
Please, Sign In to add comment