1
votes

I am trying to put the result from:

system("/14/test");

into a variable named "ZZZ" and then printf it.

#include <stdio.h>
#include <stdlib.h>

char ZZZ[10];

int main()
{

char * ZZZ = system("/14/test");

printf(ZZZ);



}

Error:

warning: initialization makes pointer from integer without a cast [-Wint-conversion]

1

1 Answers

0
votes

system() doesn't capture the output of the command it runs - just the return code of command is returned by it.

Use popen() and read from the FILE* using fgets(). Something like:

char buf[1024];
FILE *fp = popen("/14/test", "r");

while(fgets(fp, buf, sizeof buf)) {
   printf("%s\n", buf);
}