The question given like this

using the CreateProcess () in the Win32 API. In this instance, you will need to specify a separate program to be invoked from CreateProcess(). It is this separate program that will run as a child process outputting the Fibonacci sequence. Perform necessary error checking to ensure that a non-negative number is passed on the command line.

i have done like this .it doesn't show error message .when i tried to execute it exits automatically .please anyone help me ?

#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;
}

if(! CreateProcess("C:\\WINDOWS\\system32\\cmd.exe",
This needs to be something like if(! CreateProcess("C:\\Users\\me\\Documents\\Projects\\Fib\\myfib.exe", It does all the work.

This code just has to create the process and wait for it to finish.

i tried this solution.it gives infinitive loop (run time error) error .how to fix this problem?

How would I know.
You've now got two programs, and you've posted the code for neither of them.

very sorry for the inconvenience .it was mistakenly posted in c++ forum .i delete it .please reply here.all the functions
are done here .i combined createprocess() and child process to gather .where as child process is printing the Fibonacci
series .

deleted

update : didnt see it was already solved
sorry for bumping

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.