For some reasons I need a file pointer (FILE*) that points to nothing. It means I can pass it to fprintf function and fprintf ignore the file pointer.
for example:
Although as NirMH said, you can enclose it in if (nothing != NULL)
, there is another way. You can open a file in read mode (with "r"
) and when you send it to fprintf
, the write is ignored (Edit: as discussed in the comments, remember to set n=0
if it was negative as returned by fprintf
).
I personally suggest the first method though. The only reason I might do the second is if I can't change the function.
If you don't care if your code is system dependent, you can use /dev/null
in linux, nul
in windows etc,