2

I am new to C programming. In my program below, I am simply trying to immediately, exit the C program without see any additional dialog, if the programs receives the input "quit".

I am trying to accomplish this using exit(0); however, before the program exits it outputs something like

success
process exited with return value 0
Press any key to continue...

I am trying to avoid this dialog and exit the program immediately. Is this possible?

I appreciate any help with this.

Many thanks in advance!

My C Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main(void)  {
    char command1[256], command2[256];
    printf("# ");
    scanf("%s", command1);
    if(strcmp(command1,"quit")==0){
        printf("success");
        exit(0);
    }else{
        printf("unknown command");
    }

system("PAUSE");
return 0;

}
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231

5 Answers5

6

The message that you see is actually generated by the Visual Studio debugger. It's not really coming from your program.

If you would like to verify that your program is not actually displaying any message (nor waiting for a key press) just try running it from a windows command prompt. You may also try running the program in "Release" mode from withing Visual Studio. That will also confirm this.

The reason the debugger displays that information is just to help you understand what is going on with your program.

Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151
0

That output doesn't come from YOUR program, it comes from the program that runs your program. Most likely "Visual Studio", but I expect some other types of IDE's may do similar things.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
0

Can you post details of your execution environment? Seems like your process is being monitored for an exit code by another application (specialized shell perhaps) which is printing the "Press any key to continue" line

Forhad Ahmed
  • 1,761
  • 13
  • 18
0

The process exited with return value 0 certainly isn't coming from your code, rather a program in the middle of your input and the output.

I compiled this on the command line (Mac OSX) and was presented with the following output:

James:Desktop iPhone$ gcc code.c 
James:Desktop iPhone$ ./a.out
# quit
successJames:Desktop iPhone$ 

Note that I didn't reach the system("PAUSE"); either

James Webster
  • 31,873
  • 11
  • 70
  • 114
0

If you are using Dev-C++ and you would like to get rid of the message, do this:

Tools Menu -> Environment Options -> General tab

Then uncheck the Pause Program after return option.

Source: http://www.cplusplus.com/forum/general/89249/

Math
  • 3,334
  • 4
  • 36
  • 51