Skip to content

Commit b1a1c67

Browse files
author
Andreas Stieger
committed
Print file IO error texts
1 parent 0572d8a commit b1a1c67

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

‎src/main.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include<stdio.h>
99
#include<stdlib.h>
1010
#include<string.h>
11+
#include<errno.h>
1112
#ifndef_WIN32
1213
#include<libgen.h>
1314
#endif
@@ -62,7 +63,7 @@ int main(int argc, char** argv)
6263
fd=fopen(argv[i], "rb");
6364
if (fd==NULL)
6465
{
65-
printf("cannot open file: %s\n", argv[i]);
66+
fprintf(stderr, "cannot open file: %s: %s\n", argv[i], strerror(errno));
6667
return1;
6768
}
6869

@@ -75,12 +76,12 @@ int main(int argc, char** argv)
7576
}
7677
if (ferror(fd))
7778
{
78-
printf("error while reading file: %s\n", argv[i]);
79+
fprintf(stderr, "error while reading file: %s: %s\n", argv[i], strerror(errno));
7980
return1;
8081
}
8182
if (!feof(fd))
8283
{
83-
printf("not end of file?: %s\n",argv[i]);
84+
fprintf(stderr, "not end of file?: %s: %s\n",argv[i], strerror(errno));
8485
return1;
8586
}
8687

0 commit comments

Comments
(0)