hello,
how do i put the output of another program into a variable of my c-programm?
i have tried it this way, but it does not work:
does anyone know?Code:system(StringOfAskingTheOtherProgram)
scanf("%s", strMyVariable);
Printable View
hello,
how do i put the output of another program into a variable of my c-programm?
i have tried it this way, but it does not work:
does anyone know?Code:system(StringOfAskingTheOtherProgram)
scanf("%s", strMyVariable);
Yah you can do that did you heard of send message technique in Windows.
I dont know if this will be useful or not but you can #include the code and use the variable(which is your output) using extern keyword.
I'm using Linux.
Maybe it would work with unix-pipes? i don't know how.
Pipes indeed. This is an example:
This program takes the output of the linux command "ls" in "r"-mode (this is a file-mode, meaning 'read') and puts the output in upper case. All the magic is in the popen()Code:#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int main(){
int c;
FILE * ifp;
ifp = popen("ls", "r");
while ((c = getc(ifp)) != EOF)
putchar(toupper(c));
pclose(ifp);
return 0;
}
Hope this helps.