Talk:Programming OpenGL in Linux: Changing the Screen Resolution
Jump to navigation
Jump to search
Alternative to system
One could use popen instead of system and avoid the creation of files (in a potential read-only environment) The following is an example about how to do so, calling xrandr and writing it's output to stdout:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { FILE * f = popen("xrandr", "r"); char buffer [256]; int i = 0; while (feof(f) == 0) { memset(buffer, 0, 256); fread(buffer, 1, 255, f); fputs(buffer, stdout); } pclose(f); }