-3

I am opening multiple files in a while loop using fopen in C and want to be able to check if any of them will return an error. Relevant code:

int i;
for(i=0; i<10; i++) { 
  file=fopen(myList[i], "r");
}

How will I know if the file I'm currently looking at will have an error when I attempt to open it or while I am reading it?

Jimmy
  • 3
  • 1

1 Answers1

1

From man fopen:

Return Value

Upon successful completion fopen(), fdopen() and freopen() return a FILE pointer. Otherwise, NULL is returned and errno is set to indicate the error.

You can read more about errno in this three questions

Community
  • 1
  • 1
mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81