Your character array "message" needs to be large enough to accommodate "Hi Parent from Child " as well as the data in argv[1].
The way you defined it, it will only have enough storage for "Hi Parent from Child " as well as the terminating \0 null byte.
You probably will want to dynamically allocate a character array large enough to accommodate both:
This has not been tested nor syntax checked at all, so have fun with it.Code:const char message_prefix[] = "Hi Parent from Child "; char * message; /* Allocate a character array of length message_prefix + length of argv[1] * plus 1 extra character for the terminating null byte. */ if ((message = malloc(strlen(message_prefix) + strlen(argv[1]) + 1)) == 0) { /* The allocation failed for some reason. */ perror("malloc"); exit(1); } /* Copy the message_prefix to the beginning of our string. */ strcpy(message, message_prefix); /* concatenate argv[1] on the end */ strcat(message, argv[1]); /* Do stuff with your string here... */ /* ALWAYS free the dynamic allocations when you are done. */ free(message);
You'll need to include stdlib.h if you haven't already.




Reply With Quote