I\'m trying to output some string on a txt file by using c program
however, I need to see if the I have the permission to write on the txt file, if not, I need to pr
You can do some error checking to see if the calls to fopen and fprintf succeeded.
fopen's return value is the pointer to the file object on success and a NULL pointer on failure. You could check for NULL return value.
FILE *file = fopen("text.txt", "a");
if (file == NULL) {
perror("Error opening file: ");
}
Similarly fprintf return a negative number on error. You could do a if(fprintf() < 1) check.