I am trying to export variable and read it back using getenv()
but for some reason, it gives me a segmentation fault..
#include<stdio.h>
#include<stdlib.h>
int main(){
system("export LINES=$(stty size | awk '{print $1}');"
"export COLUMNS=$(stty size | awk '{print $2}')");
printf("%s %s\n", getenv("LINES"), getenv("COLUMNS"));
return 0;
}
I'm running Ubuntu 14.04.
The weird thing is that it runs normally on gdb, and the compiler output shows no error while compiling, even with -Wall -Wextra
...
Why is this happening?