1

我正在尝试从另一个程序启动一个程序。

这是下面的代码
图:1

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
int main()
{
    printf("Before Execution \n");
    system("c:\\Rasmi Personal\\PERSONAL\\C\\Code Block\\C_Test\\bin\\Debug\\C_Test.exe");
    printf("\nAfter Execution \n");
    return 0;
}

在 c:\Rasmi Personal\PERSONAL\C\Code Block\C_Test\bin\Debug\C_Test 项目中包含的代码是

图 2:

#include <stdio.h>
int main()
{
     int x = 10;
     while( x --> 0 ) // x goes to 0
     {
        printf("%d\n", x);
     } return 0;
}

但是在执行第一个程序(图 1)时,输出如下所示。

Before Execution
'c:\Rasmi' is not recognized as an internal or external command,
operable program or batch file.

After Execution

请帮我解决这个问题。

PS:- 我在 Windows XP 中使用 CODE::BLOCKS。

4

1 回答 1

4

您正在使用带有空格的路径名。当您这样做时,一切都会变得更加混乱,并且您必须在正确的位置为正确的事物添加引号才能使任何事情发挥作用。

我建议使用不带空格的路径名。

如果您仍想尝试在路径名中使用空格,则可以使用以下方法:

system("\"c:\\Rasmi Personal\\PERSONAL\\C\\Code Block\\C_Test\\bin\\Debug\\C_Test.exe\"");
于 2012-04-13T06:09:15.370 回答