質問は次のように与えられます。
Win32 API で CreateProcess () を使用します。この場合、CreateProcess() から呼び出される別のプログラムを指定する必要があります。フィボナッチ数列を出力する子プロセスとして実行されるのは、この別のプログラムです。必要なエラー チェックを実行して、コマンド ラインで負でない数値が渡されるようにします。
私は次のことをしました。エラーメッセージは表示されません。実行しようとすると、自動的に終了します。
#include <sys/types.h>
#include <windows.h>
#define _WIN32_WINNT 0x0501
#include <stdio.h>
int main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int a=0, b=1, n=a+b,i,ii;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
if(! CreateProcess("C:\\WINDOWS\\system32\\cmd.exe",NULL,NULL,NULL,FALSE,0,
NULL,NULL,&si,&pi))
printf("\nSorry! CreateProcess() failed.\n\n");
else{
printf("Enter the number of a Fibonacci Sequence:\n");
scanf("%d", &ii);
if (ii < 0)
printf("Please enter a non-negative integer!\n");
else
{
{
printf("Child is producing the Fibonacci Sequence...\n");
printf("%d %d",a,b);
for (i=0;i<ii;i++)
{
n=a+b;
printf("%d ", n);
a=b;
b=n;
}
printf("Child ends\n");
}
{
printf("Parent is waiting for child to complete...\n");
printf("Parent ends\n");
}
}
}
WaitForSingleObject(pi.hProcess, 5000);
printf("\n");
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
私は何を間違っていますか?