Home > Enterprise >  How to print something out when exiting a c program without writing to stdout [closed]
How to print something out when exiting a c program without writing to stdout [closed]

Time:10-03

How can I print a message when the program exits without sending it to stdout or to stderr? I am trying to recreate an executable that prints out a message and exits but does not produce anything in the stdout or stderr files.

I cannot think of anything for this and wasn't able to find much information on the internet. I am currently doing this to at least produce the message but it clearly does send the output to stdout.

 if (x<size){
     printf("Illegal array size\n");
     exit(1);
 }

CodePudding user response:

I am not sure I understand your question correctly. Do you want to print that statement but don't want to print in stdout or stderr streams?

If so you could could try write to a text file stored on the drive using "fprintf" command instead. You can then open the file to view the message. (It won't be visible in the terminal like it would if you write to stdout or stderr streams)

See this on how to write to a file in C: https://www.learnc.net/c-tutorial/c-write-text-file/

CodePudding user response:

You should use a conditional statement with the exit code.

  •  Tags:  
  • c
  • Related