Questions tagged [ferror]

12 questions
13
votes
2 answers

Is it possible to distinguish the error returned by fgets

Upon looking at the ISO C11 standard for fgets §7.21.7.2, 3, the return value is stated regarding the synopsis code: #include char *fgets(char* restrict s, int n, FILE* restrict stream); The fgets function returns s if successful. If…
Miket25
  • 1,895
  • 3
  • 15
  • 29
7
votes
2 answers

fread and ferror don't set errno

I'm trying to check when fread() raises an error, so I use ferror(). chunk = fread(buf, 1, 100, file); if (ferror(file)) { return errno; } But, ferror() man page (man 3 ferror, or just man ferror) says: ERRORS These functions should not…
Mahmoud Mubarak
  • 139
  • 1
  • 11
2
votes
1 answer

How does GCC interpret ferror definition?

I'm working with some embedded C code for an LCD display in which one of the files includes stdio.h and defines fputc, fgetc, and ferror. fputc calls the LCD driver code to print a character to the screen, but the other two don't actually do…
David D.
  • 59
  • 5
2
votes
2 answers

What are the possible error conditions on a stream that will cause ferror() to be set?

Some operations to read and write from streams may set the error flag in a stream, which can be tested using ferror(stream), while I'm quite sure this must be a frequently asked question, I wasn't able to find a list of all the possible causes of…
Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
1
vote
0 answers

How to signal an error in a file for ferror

Suppose I have this code: FILE *myfile=fopen("myfile.txt", "r"); if (!myfile) {...} while (1) { int c = getc(myfile); if (ferror (myfile)) { perror ("get c error"); exit (EXIT_FAILURE); } else if (c == EOF){ printf ("%s\n" ,…
kali
  • 141
  • 10
1
vote
0 answers

Error checking on stdout: is "relying on ferror" an alternative?

Does ferror() aggregate all errors of previous fputc(stdout), fputs(stdout), putc(stdout), putchar or puts calls? At least when not using wide strings?.. (Nor printf().) If it does then may it be an error checking strategy to check for errors only…
user7076126
1
vote
1 answer

Do ferrors carry through multiple writes?

Does the ferror in this example check check both fprintfs for error, or just the second one? FILE * myout; if ((myout = fopen("Assignment 11.txt", "a")) != NULL) { fprintf(myout, "First print ", str1); fprintf(myout, "Second print",…
Cullub
  • 2,901
  • 3
  • 30
  • 47
1
vote
1 answer

Trouble creating a shell in C (Seg-Fault and ferror)

I have been following a tutorial on how to make my own shell but I have been stuck for a couple days now. Two things: When this code is compiled and ran, it will randomly have segmentation faults and I cannot figure out why. The if statement `if…
Pat Murray
  • 4,125
  • 7
  • 28
  • 33
0
votes
1 answer

"ferror" tests "scanf" input

I tried to enter error data in next program but it can't recognize the error. Once I entered numeric data, and next time entered string data but the program made no reaction: #include #include #include using namespace…
pascal111
  • 37
  • 3
0
votes
3 answers

Checking stdin and stdout using external function

Does scope impact, checking for errors while obtaining input from stdin or outputting to stdout? For example if I have a code body built in the following way: void streamCheck(){ if (ferror(stdin)){ fprintf(stderr, "stdin err"); …
nutella100
  • 73
  • 6
0
votes
1 answer

C++ fwrite , ferror code 36 Broken Pipie

I have a problem with saving lot of data to binary file in c++ , i'm using CodeBlocks My code: long tablica[10000]; int main(int argc, char *argv[]) { FILE * pFile; clock_t start,stop; srand (time(NULL)); long i; for(i=0;i<10000;i++){ …
Eaxxx
  • 25
  • 3
0
votes
3 answers

How to use feof and ferror for fgets (minishell in C)

I've written this minishell but I'm not sure I'm making a correct control of the errors. I know fgets can return feof and ferror (http://www.manpagez.com/man/3/fgets/) but I don't know how to use them. I've checked if fgets returns a null pointer…
Trouble-lling
  • 333
  • 5
  • 15