Calling another program? [C]

Hi guys, I'm trying to call a program in C using system(). The nature of the program is, once I'm done registering the user using the program below, it will transfer control to the next program called by system(). The code compiles properly, but the thing is, in the

 
system("/PROJ.EXE");


line, the "PROJ.EXE" program is not called at all. Also, I'd like to know how can I trap any error (like a try-catch maybe) and display the error message on-screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int addAcct();
int checkAcct();
void printHdr();
void insertCard();

int main(){
	int opt, stat;
	FILE *fp;
	stat = 0;

	clrscr();

	insertCard();

	if (checkAcct() != 1) {
		printf("Enrolment system now loading... done!");
		printf("\n\nPress any key to continue...");
		getch();

		while ((opt!=1 || opt!=2) && stat==0){
			clrscr();
			printHdr();
			
			printf("Welcome!\n\nWould you like to sign up for our service?");
			printf("\n[1] Yes\n[2] No");
			printf("\n\nSelect option: ");
			scanf("%d", &opt);
			
			switch(opt){
				case 1:
					stat = addAcct();
					break;
				case 2:
					clrscr();
					printHdr(1);
					printf("Thank you for using our services.");
					getch();
					exit(EXIT_SUCCESS);
					break;
				default:
					printf("Invalid option. Please select from the available options.");
					getch();
					break;
			}
		}
	} else {
		clrscr();
		printHdr();
		printf("Loading account information...");
		system("/PROJ.EXE");
		getch();
	}
	
	return 0;
}
Last edited on
closed account (G309216C)
Hi,

I would strongly recommend you use function:
ShellExecute()

MSDN Documentation:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx

Usage of Function
The usage of the function is pretty straightforward keeping in mind the documentation contains all needed information:
ShellExecute(0, "open", "Echo.exe",0,"Echo", 5);

The next question you asked is quite generic in terms that in programming there are many ways to handle errors. As you specifically asked for try and catch statements Cplusplus forums documentation has it all:

http://www.cplusplus.com/doc/tutorial/exceptions/

GL
Topic archived. No new replies allowed.