I am having trouble trying to this runtime segmentation fault in this short piece of code. I suspect it has something to do with the use of system() and strcpy() in the code but as I am not experienced with this type of error, I am unsure what to do and I have not found many helpful pages so far.
The code:
#include <stdio.h>
#include <string.h>
int main(){
char command[31], string[128];
strcpy(string, (char *)system("grep -Po '(?<=testString\\s)\\S+' File"));
string[strlen(string)] = '\0';
printf("%s", string);
return 0;
}
I am using GCC 4.7.3 to compile the program. I would really appreciate any help with this a lot.