Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not checking return values in C
#1
Neglecting to check the return values of functions that can fail (e.g., malloc, fopen, etc.) can lead to errors.

// Incorrect
FILE *file = fopen("non_existent_file.txt", "r");
// No check for the success of fopen()

// Correct
FILE *file = fopen("non_existent_file.txt", "r");
if (file == NULL) {
    // Handle error (file not opened)
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function arguments and return values in C Qomplainerz 0 230 07-25-2023, 11:02 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)