Hi all,
I want to run C program as follow:
./commands filepath -l
first problem:Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char cmdline[] = "ls "; strcat(cmdline,argv[1]); // to accept filepath strcat(cmdline,argv[2]); // to accept -l system(cmdline); return 0; }
I recieved "Segmentation fault (core dumped)" for ./commands filepath
second problem:
When I passed `l': ./commands filepath -l
I recived:
ls: filepath/stuff-l: No such file or directory
Segmentation fault (core dumped)
So, it accepted filepath/stuff-l as one string
Thankx in advance



LinkBack URL
About LinkBacks


