Hi!
I am trying to run the following code.
Code:
#include <stdio.h>
#include <errno.h>
int main()
{
char s[10];
int nread;
FILE* fp;
char c;
fp = fopen("abc", "w+");
printf("error: %d, error_string: %s", errno, strerror(errno));
fprintf(fp, "Hello\n");
fseek(fp, 0, SEEK_SET);
while((c = fgetc(fp)) != EOF)
write(1, &c, 1);
fclose(fp);
return 0;
}
It compiles fine.
(none):~/prog # gcc -o err err.c
(none):~/prog #
But when I try to run it I am getting -
(none):~/prog # ./err
Hello
error: 0, error_string: Success(none):~/prog #
If I put a newline after printf like below -
Code:
printf("error: %d, error_string: %s\n", errno, strerror(errno));
I am getting the following output -
(none):~/prog # ./err
error: 0, error_string: Success
Hello
(none):~/prog #
Why does this change in sequence happen?
Thanks and regards,
Arun