C: Memory Fault (core dumped)

When I run programm show this message: Memory Fault (core dumped)

Does anyone can help me and tell me what is wrong? please

#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char *argv[]) { 


    int i=0;
    int il_krok = atoi(argv[1]);
    
    for (i=0;i< il_krok; i++)
    {
        printf("\nProces matka: %d,PID: %d krok %d z %d\n",i+1,getpid(),i+1,il_krok);
        sleep(1);
    }

    int newPid;

    for (i=1;i<argc;i++)
    {
        newPid = fork();

        if (newPid == 0)
        {
            printf("PID nowego procesu potomnego: %d", getpid());

            int j=0;
            il_krok = atoi(argv[i+1]);

            for (j=0;j< atoi(argv[i+1]); j++)
            {
                printf("\nProces id: %d,PID: %d krok %d z %d\n",i+1,getpid(),j+1,il_krok);
                sleep(1);
            }

            return (i+1);

            int status = 0;
            int pid = wait(&status);

            printf("Proces zakonczony: PID: %d Status: %d \n",pid, WEXITSTATUS(status));
        }

        else
        {
            int status = 0;
            int pid = wait(&status);

            printf("Proces zakonczony: PID: %d Status: %d \n",pid, WEXITSTATUS(status));

        }

    }

    return EXIT_SUCCESS;
}

When i is argc-1, atoi will dereference a null pointer.

On an unrelated note, atoi performs little to no checks on the validity of its input and can return garbage. The sooner you top using it, the better.

To use WEXITSTATUS correctly, first you must consult WIFEXITED.

Perhaps there are other problems, but I only skimmed the code.

Regards and welcome to the forum,
Alister

Sorry, but i don't understand. I am a beginer and I dont know how to do it correcly.

One way perhaps:

char *string="12345";
int value;

if(sscanf(string, "%d", &value) != 1)
{
        fprintf(stderr, "'%s' is not a number\n", string);
}