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


Messages In This Thread
Not checking return values in C - by Qomplainerz - 07-26-2023, 07:12 AM

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

Forum Jump:


Users browsing this thread: 3 Guest(s)