I need to pass two args to a shell script, here is the code:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char *script;
int lines = 1;
sprintf(script, "/...path.../line.sh %d %d", lines, lines);
system(script);
}
The script works well, ive tried. But I always get Segmentation fault. The question is: why?
Thanks
You are writing to the memory location pointed to by
scriptwhich hasn’t been allocated any memory.Try something like: